- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-09-2017 10:31 AM
Hi All,
I have a requirement where I have to validate a single line text field to have alpha-numeric characters. I have written this onChange script as below, but I think it's not working as expected.
please help me.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
g_form.hideFieldMsg('SAP Customer Number');
var patt = "^[a-zA-Z0-9]*$";
if (!patt.test(newValue))
g_form.showFieldMsg('SAP Customer Number','Invalid input','error');
var patt2 = "^[Nn]/[Aa]$";
if (!patt.test(newValue))
g_form.showFieldMsg('SAP Customer Number','Invalid input','error');
}
Thanks in Advance,
SD
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-09-2017 10:57 AM
I understood the requirement. This time though, I'll repeat the earlier statement and show you the code.
you dont need a regeexp for that. Use .length property of newValue to check.
translates to
var patt = new RegExp("^[a-zA-Z0-9]*$");
if(!patt.test(newValue) || newValue.length != "10"){
// error out.
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-09-2017 10:36 AM
You are missing constructor.
You should do :
var patt = new RegExp("^[a-zA-Z0-9]*$");
test() is not a method of String class. It's a method of RegExp class.
Also you can just use var rege = new RegExp("^[a-zA-Z0-9_]*$"); rege.test(newValue) to test for alpha numeric.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-09-2017 10:51 AM
Hello Abhiram,
Thanks for your response. This works perfectly. But I need this Alpha-numeric to be 10 Characters only.
How can I do that??
Thanks,
SD
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-09-2017 10:53 AM
you dont need a regeexp for that. Use .length property of newValue to check.
Mark this as answered if its working.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-09-2017 10:55 AM
Hi Abhiram,
I don't think you understand the requirement.
I need the alpha numeric to be 10 Characters only. Not less than 10 and not more than 10.
Could you please help me here with the script.
Thanks,
SD