
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2023 08:29 PM
I have a requirement to be implemented for a field. For which I need to implement onChange script with below validation:
Alphanumeric combination of 14 digits where the value should start with "A" and only "-" is allowed as special character.
Please help me in implementing this requirement.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2023 09:34 PM - edited 09-20-2023 09:54 PM
Hello @Deepika Mishra
Please try below code segment
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var regex = /^A[A-Za-z0-9-]{13}$/;
var name = g_form.getValue('u_name');
if(regex.test(name) == false){
g_form.showFieldMsg('u_name','String should start with A and must contain 14 digits, Hyper (-) only allowed','error');
}
}
Please mark my answer helpful, if it helps you
Thank you
Thank you
G Ramana Murthy
ServiceNow Developer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2023 09:52 PM - edited 09-20-2023 10:01 PM
Make use of ChatGPT know
here is the output :
^A[a-zA-Z0-9-]{13}$
'A' - Match character A
[a-zA-Z0-9-] - match any alpha numeric character or -
{13} - preceding character
Client Script :
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var regex = /^A[a-zA-Z0-9-]{13}$/;
if(!regex.test(newValue)){
g_form.showFieldMsg("Your field name","Please enter valid character",Error);
} else {
//g_form.clearValue('Your field name');
g_form.clearMessages();
}
}
ServiceNow Developer
I know one thing, and that is that I know nothing.
- Socrates