Validation against a text variable on form
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-10-2022 11:48 PM
Dear All,
Can any one help me on below requirement?
There is a multi line text type variable named Report ID-Company Code on a form and this field should only accept values in below format,
Report ID (Maximum 32 characters, but only alpha-numerical) - Company Code(Maximum 8 and minimum 6 characters, but only alpha-numerical) . Multiple values required to be separated by Commas.
For Example: ytegfs234sdhkl8291ghta1b345yur23A-RTS768gh,gtsr34klas90wevbter2h1b345yur23M-vnk751gh,o1b785yurtgbfts890ADG34bhu290kma-mdr768g,DFGTWERUI3478gho-qwoprt
Kindly help!
***No spaces are allowed.
Thank You,
Anoop
Thank You,
Anop

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-11-2022 12:38 AM
Hi Anoop
You can set the maximum field size for each field in the dictionary. Right click the field and select Show Dictionary and change the value.
You should use an onChange client script on these fields. You can do the text validation with regex.
Here is an example of one I wrote last week.
This script does not allow special characters or numbers.
Form field cannot contain numbers or special chars:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var regexp = /^[A-Za-z ]+$/;
if(!regexp.test(newValue)){
alert('short description cannot contain numbers');
g_form.u_short_description = ''; //do something
}
//Type appropriate comment here, and begin script below
}
You should investigate Regex do build your condition:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions/Cheatsheet
Hope this helps.
Please mark my answer as Correct/Helpful based on impact
Regards,
Dan H
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-11-2022 01:21 AM
I think it would be handy to have 2 variables and a client script on that.
Client script could look something like this for OnChange.
Report ID:
var string = "APSOFPOASKF2340AOSFJ";
if(string.length <= 32){
//var regex = /[a-zA-Z0-9]{1,32}/;
var regex = /[ `!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?~]/
if(!string.match(regex)){
gs.info("Yess this is the right input");
} else {
gs.info("You are not allowed to put in special characters (also no spaces).")
}
} else {
gs.info("It's too long");
}
Company ID:
var string = "13";
if(string.length >= 6 && string.length <= 8){
//var regex = /[a-zA-Z0-9]{1,32}/;
var regex = /[ `!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?~]/
if(!string.match(regex)){
gs.info("Yess this is the right input");
} else {
gs.info("You are not allowed to put in special characters (also no spaces).")
}
} else {
gs.info("Needs to be between 3-6 characters");
}
Hope this helps.
Please mark my answer as Correct/Helpful based on impact
Regards,
Robin
Kr!
Robin