Field Data validation

aastha3
Giga Contributor

Looking for field data validation

1. It should start begin with an alpha character

2. Can only be (a-z) lower case

3.(0-9) numbers

4. "-" (hyphen) character.

Please also suggest if it should work on Onload , On change or onsubmit.

There is a field   of a catalog named hostname(single text line) on which this validation is required.

Thanks

1 ACCEPTED SOLUTION

Try below:-



var regexp=/^[a-z]{1}[a-z0-9-]*$/;



if(!regexp.test(newValue)){


alert('Please enter valid characters");


g_form.setValue('ur_name','');


}


Mark Correct if it solved your issue or hit Like and Helpful if you find my response worthy.


Thanks,
Deepa


View solution in original post

10 REPLIES 10

Deepa Srivastav
Kilo Sage

Hi Aastha,



You should use it onChange of the field...


Below thread might help you..




https://community.servicenow.com/message/947083#947083



Also below expression will fulfill your first three requirement.



var regexp = /^([a-z]){1}(\w*)$/;




Mark Correct if it solved your issue or hit Like and Helpful if you find my response worthy.


Thanks,
Deepa


Not working to include hyphen "-"


Try below:-



var regexp=/^[a-z]{1}[a-z0-9-]*$/;



if(!regexp.test(newValue)){


alert('Please enter valid characters");


g_form.setValue('ur_name','');


}


Mark Correct if it solved your issue or hit Like and Helpful if you find my response worthy.


Thanks,
Deepa


Yes now its working   but showing warning as WARNING at line 5: Unescaped '-'.