Numeric digit restriction
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-09-2024 12:03 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-09-2024 12:08 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-09-2024 12:10 AM - edited ‎02-09-2024 12:44 AM
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
}
Regards,
Piyush Sain

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-09-2024 12:24 AM - edited ‎02-09-2024 12:25 AM
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");
}
Aman Kumar