adding script to validate entry only includes numeric values

patricklatella
Mega Sage

hi all,

I've seen several posts about this but am having trouble adding in the script needed to validate that the entry in a field only contains numbers.   I already have an onChange client script validating that the entry in a field is 6 characters, but I need to also ensure the entry only contains numbers.

here's my existing script...can anyone help with the needed additional script?   thanks!

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

g_form.hideErrorBox('emp_workday_id');

if(!isLoading){

//check that the entry in the field is 6 digits

var empNumber = g_form.getValue('emp_workday_id');

if(empNumber.length!=6){ //check to see if emp workday id matches 6 numbers long

g_form.showErrorBox('emp_workday_id','Entry must be a 6 digit number');

return;

}

}

}

1 ACCEPTED SOLUTION

Prateek kumar
Mega Sage

Hello Patrick


Can we try something like this



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


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


return;


}


var pattern = /^[0-9]*$/;


if(!pattern.test(newValue)|| (newValue.length != 6))// adjust your digits.


{


alert('please enter only digits and min length should be 6');


g_form.setValue('u_variable1', ''); // adjust field name accordingly if you want to blank it out.


}


}



Please mark my response as correct and helpful if it helped solved your question.
-Thanks

View solution in original post

3 REPLIES 3

Prateek kumar
Mega Sage

Hello Patrick


Can we try something like this



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


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


return;


}


var pattern = /^[0-9]*$/;


if(!pattern.test(newValue)|| (newValue.length != 6))// adjust your digits.


{


alert('please enter only digits and min length should be 6');


g_form.setValue('u_variable1', ''); // adjust field name accordingly if you want to blank it out.


}


}



Please mark my response as correct and helpful if it helped solved your question.
-Thanks

works perfectly, thanks Prateek!


Prateek kumar
Mega Sage

Great, Cheers mate!



Please mark my response as correct and helpful if it helped solved your question.
-Thanks