If zip code starts with a zero, then the first zero from the zip code should be dropped

Ankita9
Tera Contributor

Hi All,

 

I have a requirement where, If zip code starts with a zero, then the first zero from the zip code should be dropped.

for eg : 03011 should show as 3011.

 

Can someone please help me with the below script corrections.

 

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
    var pc = g_form.getValue('postal_code');
 
    if (pc.indexOf('0') == 0) {
 
      alert('pc contains' +pc);
  g_form.setValue('postal_code', pr.trim(1));
    }
}
2 REPLIES 2

Anil Lande
Kilo Patron

Hi,

Try below script:

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
    var pc = g_form.getValue('postal_code');
	alert(pc);
 
    if (pc.indexOf('0') == 0) {
 
      alert('pc contains' +pc);
  g_form.setValue('postal_code', pc.substring(1));
    }
}

I hope client script is configured to run on change of 'Postal Code' field.

 

Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande

piyushsain
Tera Guru
Tera Guru

Use substring() instead of trim()

If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.
Regards,
Piyush Sain