How to check regular expression for a text field.

keerthi19
Tera Guru

How to check regular expression for a text field. For example: In the text field user should needs to enter only 552 to 574 numbers .they should enter only numeric number within the specified numbers.how can we check this using regular expression or any other way.

1 ACCEPTED SOLUTION

Hi,



Try this regex: ^azwv51((75|76|77|78|79)|[8-9][0-9])$


View solution in original post

5 REPLIES 5

nishailame
ServiceNow Employee
ServiceNow Employee

If you want to check on form, then use below.


Create onSubmit client script.



In script,   perform checks on input values.


var input = g_form.getValue(""); --> column name


if( typeof input == number &&   parseInt(input) < = 574 &&   parseInt(input) > = 552)



Community Code Snippets: Some Observations on parseInt, and parseFloat



And if you want to include in HTML, You can find regex online. There are many ways to achieve it.


ex. string.match(/^[0-9]+$/) != null; , var isNumber =   /^\d+$/.test(theValue);



 


Thanks.


PS: Hit like, Helpful, Correct and Endorse, if it answers your question.


Hi Nisha,



Thanks for the input. I tried but no luck.


I am trying


var regexp= new RegExp("^azwv[5175-5199]{4}$");


if(!regexp.test(val) ){


  g_form.showErrorBox("servername","Enter server id as following format within the available numbers (5175-5199) (e.g.,azwv5175 ) ");


it is working partially. It is taking only 5175 and 5199 but it needs to take from 5175 to 5199. Something is missing in the code. can anyone help?


Hi,



Try this regex: ^azwv51((75|76|77|78|79)|[8-9][0-9])$


Hi Vitaly,


Sorry, but this regex looks really interesting. Can you please explain how this works?