The CreatorCon Call for Content is officially open! Get started here.

URL validation

Anna L
Tera Contributor

Hi, How would I validate a URL field on my request item form based on following criteria:

It should be entered by user in form of:

jb**.systemaudit.com

Basically it should stop user for submitting the request, so an onsubmit script,   Any script suggestions?

1 ACCEPTED SOLUTION

Here you, these are the 2 versions I have got for you


1) It takes any two characters(this include digits)


function onSubmit() {


  if(!(/jb.{2}.systemaudit.com/g.test(g_form.getValue("your field name goes here")))){


  alert("please enter in desired format");


  return false;


  }




2)It takes only 2 digits


function onSubmit() {


  if(!(/jb(\d){2}.systemaudit.com/g.test(g_form.getValue("your field name goes here")))){


  alert("please enter in desired format");


  return false;


  }


View solution in original post

6 REPLIES 6

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hi,



You may find below thread helpful.


URL validation for a request form


Chuck Tomasi
Tera Patron

Hi,



You could do this with a regular expression. I take it that ** represents any two characters, so jb01.systemaudit.com jbZZ.systemaudit.com and jb-$.systemaudit.com are all valid values, correct?


Abhinay Erra
Giga Sage

Use this



function onSubmit() {


  if(!(/jb.*.systemaudit.com/g.test(g_form.getValue("your field name goes here")))){


  alert("please enter in desired format");


  return false;


  }


It works great. One question though, it also works for jb87systemaudit.com, basically it should not accept this.



jb87.systemaudit.com is correct that works.



How to make sure   jb87systemaudit.com doesnt work?