How can I restrict a field to accept alphanumeric values - first 2 characters use alphabets?

KS13
Tera Contributor

How can I restrict a field to accept alpha numerical values? 

First 2 characters are alphabets

Following 5 characters are numerical 0-9.

I would prefer using an OnChange script if possible.

1 ACCEPTED SOLUTION

Rahul RJ
Giga Sage
Giga Sage

@KS13  you try the below code  on change client script

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   if (isLoading || newValue === '') {
      return;
   }
var rexp = '^[a-zA-Z]{2}[0-9]{5}$';
var dataValue=g_form.getValue('description'); //field name or you direct use new Value

if(dataValue.match(rexp)==null){
	g_form.addErrorMessage('please provide First 2 characters are alphabets and rest numbers');
}
else{
	g_form.addInfoMessage('looks good')
}
   //Type appropriate comment here, and begin script below
   
}

 

Please mark the answer correct/helpful based on Impact.

Regards,

RJ

 

View solution in original post

3 REPLIES 3

Rahul RJ
Giga Sage
Giga Sage

@KS13  you try the below code  on change client script

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   if (isLoading || newValue === '') {
      return;
   }
var rexp = '^[a-zA-Z]{2}[0-9]{5}$';
var dataValue=g_form.getValue('description'); //field name or you direct use new Value

if(dataValue.match(rexp)==null){
	g_form.addErrorMessage('please provide First 2 characters are alphabets and rest numbers');
}
else{
	g_form.addInfoMessage('looks good')
}
   //Type appropriate comment here, and begin script below
   
}

 

Please mark the answer correct/helpful based on Impact.

Regards,

RJ

 

KS13
Tera Contributor

Thank you Rahul, the solution provided worked. 👍

KS13
Tera Contributor

Hi Rahul, 

Thank you for helping me out yesterday!

However I did run into an issue.  

It does throw the error message but it still allows the user to submit after the error is exed out. It should not allow the user to proceed unless the ID is accurately formatted. 

Also, it does not clear the values if the ID is inaccurately formatted.