Phone number(E16) type is accepting alphabets

Community Alums
Not applicable

Hi,

I have a phone number field which is phone number(E16) type when am giving alphabets it is accepting without throwing any validation error. Can anyone help me on this how should i restrict alpha numeric validation on E16 type.

4 REPLIES 4

Rohini S Sane
Tera Guru

Hello @Community Alums ,

You can use regex to restrict alphabets.

 

Regards,

Rohini Sane

 

Community Alums
Not applicable

HI, 

Tried with this but not working 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   if (isLoading || newValue === '') {
      return;
   }
var regex = /^[\d\s]{10,20}$/;

    if (newValue != '' && !regex.test(newValue)) {
        g_form.clearValue('u_contact_information');
        g_form.showFieldMsg("u_contact_information", "Invalid phone", "error");
    }
   //Type appropriate comment here, and begin script below
   
}

Sumanth16
Kilo Patron

Hi @Community Alums ,

 

Please create onchange client script:

function onChange(control, oldValue, newValue, isLoading) {
if(isLoading || newValue == ''){
return;
}
// Allows formats of (999) 999-9999, 999-999-9999, and 9999999999
var pattern = /^[(]?(\d{3})[)]?[-|\s]?(\d{3})[-|\s]?(\d{4})$/;
if(!pattern.test(newValue)){
alert('Phone enter a valid phone number');
g_form.setValue('u_mobile_number', '');
}
}

 

If I could help you with your Query then, please hit the Thumb Icon and mark it as Correct !!

 

Thanks & Regards,

Sumanth Meda

Community Alums
Not applicable

tried with this, still error message is not coming and able to save with alphabets