- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-21-2016 09:00 PM
Hello there,
I am trying to build some requirement here which goes like:-
i want to validate a particular field with minimum 6 characters without spaces.
I mean to say is if the user types "abcdef"(6 characters without space) or "a a a a a a"(6 characters with space) etc., the script should return true else it should return false.
i have already tried that with a script but its not working for me:-
function onSubmit() {
//Type appropriate comment here, and begin script below
var check = g_form.getValue('my variable field name here');
var ok= /^\s*(\S\s*){6,}$/;
if(check.test(ok))
{
alert('Please Enter an appropriate name!');
return false;
}
else{
return true;
}
}
So any ideas on this?
Thanks,
Shahid
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-22-2016 04:53 AM
return true condition you have written in two different lines. Thats why it is returning true if any of those conditions met.
Please use your script like below:
function onSubmit() {
var character1 = g_form.getValue('field1');
var character2 = g_form.getValue('field2');
var str1 = character1.replace(/ /g,"");
var str2 = character2.replace(/ /g,"");
if(str1.length >= 6 && str2.length >= 6 ){
return true;
}
else{
if(str1.length < 6){
alert('Please be appropriate in filling out the field "Field1"');
}
if(str2.length < 6){
alert('Please be appropriate in filling out the field "Field2"');
}
if(str1.length < 6 && str2.length < 6){
alert('Please be appropriate in filling out the field "Field1" and "Field2 "');
}
return false;
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-23-2016 11:09 PM
Hi Mihir,
Your script finally worked well.
But there was only one problem in your script that your script was checking the character limit for multiple fields at a single go, hence popping up all the alerts at a time which might confuse the user:- as you have used only If conditions in it.
So to avoid that we can use if () {} -- else if () {} -- .......for as many fields you want to validate. Apparently, same will be the no of "if" and "else ifs" conditions ,depending on the no of fields you want to validate. (Inside the else condition of your script).
Therefore each time the user submits the record, the script will keep on reminding the user with an alert each time of the submission.
Thanks for the script though, it works great!
RGDS,
Shahid
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-22-2016 05:02 AM
This expresion is kinda tricki because you have 6 characters and 5 space... I create it on fast and test on my instance. It works But you can put space after last character i dont have more time to upgrade regular expression. Check this please. If u want it on Submit just change function from onChange to onSubmit.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var insertCode = g_form.getValue('u_requester_name');
var matchPattern = /^([a-zA-Z][\s]?){6}$/;
var myResult = matchPattern.test(insertCode);
if (insertCode == '')
g_form.hideErrorBox("u_requester_name");
else if(!myResult){
g_form.hideErrorBox("u_requester_name");
g_form.clearValue('u_requester_name');
g_form.showErrorBox("u_requester_name", "Error text here");
}
else
g_form.hideErrorBox("u_requester_name");
}
Best,
Artur