- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-07-2018 04:07 PM
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;
}
}
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-07-2018 04:36 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-07-2018 04:36 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-07-2018 05:29 PM
works perfectly, thanks Prateek!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-07-2018 05:52 PM
Great, Cheers mate!
Please mark my response as correct and helpful if it helped solved your question.
-Thanks