Looking for a Javascript solution to provide validation on a text field
The text field can only accept entries of 4 letter code (A-Z) entries, accept a minimum of 1 entry, a maximum of 3 entries. Example:
AMTX; CIOH; CLOH is a valid entry
-
Good afternoon Tracy Vymola,
Just to keep you informed.
We are analyzing you case, we will return to you as soon as possible.
Thank you for your understanding.
Best Regards
Rosario Matos
0 -
Hi Tracy,
if it is in skybow Rich Forms or skybow Solution Studio online, please first select the field you want to validate, and then click on the function button beside the "Validation" rule for that field:

The skybow expression editor will open. Please choose the "Function code" option from the drop down in the top of the window, and use the following expression in the code block:
var regexrule = /^[A-Z]{4}$/;
return (regexrule.test([[WineDescription]]));"^[A-Z]{4}$" is regex expression you need for this validation (4 capital letters A-Z). Regex expressions are part of every programming or configuration language, and they are used exactly to provide custom, specific validations, such as this one.
Of course, you will replace the "[[WineDescription]]" with your field name, or just select it from the list on the right side.
Clicking on the "Test" button you can prove if the validation works.

Click on the "Save" button, and that will the expression builder.
The last thing you need to set is a user-friendly validation message. You will do that in the Validation Text box, for the same control. You can enter there something like "Wine description needs to have 4 capital letters":

On the end, save the form, and test it. The validation should be in place:

I hope this can help
Best regards, Adis
0 -
Adis, thank you so much for your help with this. Your recommendation does work for the validation of a single entry. Is it possible to allow up to 3 entries in total for this field?
0 -
Well, it all depends what exactly do you want achieve, how do you separate entries (comma, semicolon...), are there empty spaces after separators, etc. Regex is technology independent, very flexible rule engine, and it is there to help you to create any complex string (text) validation rules you might have.
Your example from above would be covered with this regex rule:
/^([A-Z]{4})(([,;]([ ]{0,1}))([A-Z]{4})){0,2}$/
This rule takes minimum of one series of 4 A-Z letters, but expects maximum two more series, preceded with a comma (,) or semicolon (;). A space can follow a separator (comma, semicolon), but it does not have to.
If you need more separators, if spaces should, or should not be optional, or if some other rule changes, you will have to modify the regex rule above. I can recommend you www . regexr . com site, which is a great resource for learning, understanding and online building regex expressions.
RegExr: Learn, Build, & Test RegEx
Hope this could help.
0 -
Good day Adis, thank you so much for your help with this expression. Plugged it in and tested. Confirmed that it is behaving as desired. Thank you so much for your help. I have bookmarked the Reg Ex site for future reference.
0
Please sign in to leave a comment.
Comments
5 comments