- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-24-2023 09:39 AM
Yesterday, a solution was provided for the same question, but after the error message was closed, it still allowed the user to submit with the inaccurate format.
Have written the following script and still not working:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var rexp = '/^[a-zA-Z]{2}[0-9]{5}]$/';
var dataValue=g_form.getValue('provide_id');
if (dataValue.match(rexp)==null){
alert('The new ID format does match the ID format.');
g_form.clearValue('provide_id');
g_form.showFieldMsg('provide_id', 'The new ID format does match the ID format.', 'info', true);
} else {
g_form.clearMessages();
}
}
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-26-2023 02:04 PM
What is the issue ? I havent adjusted is fully for your use case - you can check if the first input keystroke is alphabetic, if second is alphabetic, is third is numeric, etc.
Try this (I tested it on my PDI for several use cases - allows input if, first & second input is character, 3-5 are numbers. If > 7 - error)
function onLoad() {
var control = g_form.getControl('provide_id');
Event.observe(control, 'input', function(e) {
var oldInputVal = e.target.defaultValue;
var newInputVal = e.target.value;
var regexMandatoryChars = /^[a-zA-Z]{2}/gm;
var regexLastChars = /\d{5}$/gm;
var regex1Char = /[a-zA-Z]$/gm;
var regex2Char = /[a-zA-Z]$/gm;
var regex3Char = /\d$/gm;
var regex4Char = /\d/gm;
var regex5Char = /\d/gm;
var regex6Char = /\d/gm;
var regex7Char = /\d/gm;
var oldInput = (function () {
var i = oldInputVal;
return {
get: function () {
return i;
},
set: function (val) {
i = val;
}
};
})();
var userVal = newInputVal;///.replace(regexSpecialChars, "");
if(userVal.length == 1){
if(!regex1Char.test(userVal)){
alert("First two characters must be alphabetical! You typed " + userVal + ", type an alphabetical character instead!");
userVal = userVal.replace(/.$/, "");
}
} else if(userVal.length == 2){
if(!regex2Char.test(userVal)){
alert("First two characters must be alphabetical! You typed " + userVal + ", type an alphabetical character as a second one instead!");
userVal = userVal.replace(/.$/, "");
}
} else if(userVal.length == 3){
if(!regex3Char.test(userVal)){
alert("Last 5 characters must be numeric. " + userVal + " is not a number!");
userVal = userVal.replace(/.$/, "");
}
} if(userVal.length == 4){
if(!regex3Char.test(userVal)){
alert("Last 5 characters must be numeric. " + userVal + " is not a number!");
userVal = userVal.replace(/.$/, "");
}
} if(userVal.length == 5){
if(!regex3Char.test(userVal)){
alert("Last 5 characters must be numeric. " + userVal + " is not a number!");
userVal = userVal.replace(/.$/, "");
}
} if(userVal.length == 6){
if(!regex3Char.test(userVal)){
alert("Last 5 characters must be numeric. " + userVal + " is not a number!");
userVal = userVal.replace(/.$/, "");
}
} if(userVal.length == 7){
if(!regex3Char.test(userVal)){
alert("Last 5 characters must be numeric. " + userVal + " is not a number!");
userVal = userVal.replace(/.$/, "");
}
} if(userVal.length > 7){
userVal = userVal.replace(/.$/, "");
alert("Allowed lenght [2 characters and 5 numbers] reached. No more characters allowed!");
}
oldInput.set(userVal);
g_form.setValue('provide_id', oldInput.get());
});
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-24-2023 09:50 AM
You are clearing the value of the field after the alert - is this working? Is the field mandatory?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-24-2023 10:03 AM
Hi Brad,
Thank you for responding, The field is mandatory. Yes, after the user clicks ok on the pop error message, the field then clears previous values.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-24-2023 10:28 AM
I'm confused how the user can submit an incorrect format after closing the error message then. Are you saying the regex / validation is not working - so they don't get the error message when they should?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-24-2023 10:52 AM
You are right Brad. I think regex/validation is not working.