Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-09-2019 12:15 PM
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);
}
}
}