We're reclaiming inactive PDIs to keep them available for active builders. Learn what's changing, who's affected, and how to protect your work. Read More

IP address validation

lucky24
Tera Contributor

Hi Team,

I have to validate IP address.

IP address should be range from 0 to 255 and should be Like 165.237.245.224.

 

How can I achieve above asking?

Thanks

2 REPLIES 2

Ankur Bawiskar
Tera Patron

@lucky24 

I have created blog for this. have a look

IP Address Validation Client Side 

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

Tai Vu
Kilo Patron

Hi @lucky24 

OOTB there's existing Field Type and Variable Type for IP Address (Validated IPV4, IPV6).

Ref: IP address field type

 
If you're working with Catalog Variables, you can define your own Validation Regex in the Question Regular Expressions [question_regex].
TaiVu_0-1700118890125.png
TaiVu_1-1700118961967.png

 

You can also create a Client Script to validate it.

 Sample

 

var regex =  /^([0-9]{3})+([-]{1})+((0-9)]{2})+([-]{1})+([0-9]{4})$/;  //Replace your regex validation
if (!regex.test(newValue)) {
     g_form.clearValue('<your_field_name>');
     g_form.showFieldMsg('<your_field_name>', 'Not a valid IP Address ', 'error', true);
} 

 

 
Cheers,
Tai Vu