Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Check if some of the characters are numbers

user_ms
Tera Expert

Extract characters and check if the extracted value is a number.

 

If there is the following value, I want to extract the first 3 characters and determine whether the value is a number.
123-456

If there is no number, print an error message in the field.

 

Other conditions
Use Client Script
Check with onSubmit

 

Please let me know if you know.

1 ACCEPTED SOLUTION

Sandeep Rajput
Tera Patron
Tera Patron

@user_ms Here is the script 

function onSubmit() {
   //Type appropriate comment here, and begin script below
	var textBox= g_form.getValue('text_box');
	var pattern = /^\d{3}-/;
	if(pattern.test(textBox)){
		g_form.showFieldMsg('text_box','correct');
	}
	else{
		g_form.showFieldMsg('text_box','incorrect');
	}
	return false;
}

View solution in original post

5 REPLIES 5

Harish Bainsla
Kilo Patron
Kilo Patron

hi

function onSubmit() {

var fieldValue = g_form.getValue('your_field');

var firstThreeChars = fieldValue.substring(0, 3);

if (!isNaN(firstThreeChars)) {

} else {

g_form.addErrorMessage("The first three characters must be a number.");
return false;
}