Numeric digit restriction

Vaka Krishna
Tera Contributor

Hi Community,

I have a requirement where single line text field shouldn't contain more than four numeric digits and it should allow characters.

example:

Krishn12_krishn43: single line text should allow this string

Krishn123_krishn43: single line text shouldn't allow this string as it is having 5 digits.

 

3 REPLIES 3

piyushsain
Tera Guru
Tera Guru

Hi,

Please use the below script

 

var noChars = current.string_field_name;
var regexp = /^(?!(.*\d){6,})[a-zA-Z\d]*$/;
if(regexp.test(noChars)){

}
else{
//add error message
}

 

 

If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.
Regards,
Piyush Sain

Aman Kumar S
Kilo Patron

You can use below onChange client script:

 

var str = newValue; 
// Using match with regEx
var matches = str.replace(/[^0-9]/g, "");
if(matches.length >4){
g_form.showFieldMsg("your_field_name", "More than 4 digits","error");
g_form.clearValue("your_field_name");
}

 

Best Regards
Aman Kumar