- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-03-2017 12:03 PM
Hi Folks,
I am trying to validate an alpha-numeric field of length 10 in a catalog item. It's giving me an error even though I have used the alpha-numeric. I am doing this by onChange client script.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
g_form.hideFieldMsg('sap_customer_number');
var patt =new RegExp("^[a-zA-Z0-9]*$");
if (!patt.test(newValue)||patt.length !="10")
g_form.showFieldMsg('sap_customer_number','Invalid input','error');
}
Here are the results when I used this script:
Thanks in Advance,
SD
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-03-2017 01:13 PM
That's strange, since it worked in my developer instance. Here's the full script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
g_form.hideFieldMsg('sap_customer_number');
var patt = new RegExp("^[a-zA-Z0-9]*$");
if (!patt.test(newValue + '') || newValue.length !="10")
g_form.showFieldMsg('sap_customer_number','Invalid input','error');
}
The only other thing I did was force newValue to a string in line 8.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-03-2017 12:18 PM
Hi,
Try this
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
g_form.hideFieldMsg('yourfField');
var patt = "^[a-zA-Z0-9]*$";
if ((!patt.test(newValue)) || pat.length != '10')
g_form.showFieldMsg('yourField', 'Invalid input', 'error');
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-03-2017 01:08 PM
Hello Bharath,
Tried this didn't work. It is no throwing error of the field length increases or decreases 10.
Thanks,
SD
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-03-2017 12:22 PM
It looks like your second or condition is wrong. Where you have
patt.length !="10"
should be
newValue.length != "10"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-03-2017 01:07 PM
Hi Fredflintstone,
Tried this didn't work.
Thanks,
SD