Validating Single line text field to allow enter number from 1 to 24.

Tinku Kajariya
Giga Contributor

Hi Developer,

I need help in validating single line text field so that end user can enter numbers from 1 to 24 only.

@Ankur Bawiskar @Anil Lande please help me for this.

 

Regards

Tinku

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@Tinku Kajariya 

simply create variable validation regex and add the regex

then link this with your text variable and no script required

^(0?[1-9]|1[0-9]|2[0-4])\b$

1) create new from this

find_real_file.png

2) fill details as this

find_real_file.png

3) Link to that variable

find_real_file.png

Output

find_real_file.png

 

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

4 REPLIES 4

Martin Ivanov
Giga Sage
Giga Sage

client script - on change of the respective field

if(parseInt(newValue) <1 || parseInt(newValue)>24){

g_form.setValue('your field', '');

g_form.g_form.showFieldMsg('your field', 'Value must be between 1 and 24');

}

Please Mark Correct AND Helpful. Thanks


Please mark Correct and click the Thumb up if my answer helps you resolve your issue. Thanks!
Martin Ivanov
ServiceNow MVP 2023, 2024

Hi @Martin Ivanov ,

Above script is not working at all. Can you have something else for this?

Check my below working response

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Ankur Bawiskar
Tera Patron
Tera Patron

@Tinku Kajariya 

simply create variable validation regex and add the regex

then link this with your text variable and no script required

^(0?[1-9]|1[0-9]|2[0-4])\b$

1) create new from this

find_real_file.png

2) fill details as this

find_real_file.png

3) Link to that variable

find_real_file.png

Output

find_real_file.png

 

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader