Narendra, I tried the code from the article, it's not working.

nrd5830
Mega Guru

Narendra,

I tried below onChange script, it worked,

 

function onChange(control, oldValue, newValue, isLoading) {


if(isLoading || newValue == ''){


return;


}
var pattern = /^\(\d{3}\)\s\d{3}-\d{4}$/; //(xxx) xxx-xxxx


var phone = g_form.getValue('emer_contact');


if(!pattern.test(phone)){


phone = phone.replace(/\D/g,'');


var regex = /^\d{10}$/;


var is_valid = regex.test(phone);


if(!is_valid){


g_form.addInfoMessage('Invalid phone number. Please enter 10 digits');


g_form.clearValue('emer_contact');


}else{


phone = '(' + phone.slice(0,3) + ') ' + phone.slice(3,6)+'-' + phone.slice(6,10);


g_form.setValue('emer_contact', phone);


}


}


}

View solution in original post

This worked well for me! Thank you very much for coming back and adding what you did!  Makes community better!

Hello Nitish,

Thank you for uploading this script - It worked perfectly!

With kind regards,

Eamonn