field validation on a form - alpha numeric only

mborkowski
Tera Contributor

Hello all
I have a request to update an existing field on Incident form to a specific format as users are entering garbage data in the field now..

 

Entry should be restricted to alpha-numeric (for example: 123X)

 

What's the easiest way to accomplishing this? 
thanks for your help

2 REPLIES 2

SVimes
Kilo Sage

I suppose this depends on needs, but one way is through a Client Script (onChange for the respective field) where you do a regular expression evaluation like this:

var str = newValue;
str = str.replace(/[A-Za-z0-9]/g,"");
if (str != "") {
   g_form.clearValue("<field>")
}
Sable Vimes - CSA

Another example (maybe simpler)

var useRegEx = /[^A-Za-z0-9]/;
var str = newValue;
if (useRegEx.test(str)) {
   g_form.clearValue("<field>");
}
Sable Vimes - CSA