Altair Posted April 17, 2020 Report Share Posted April 17, 2020 How do I make my fields check and validate if the entered field is following a specified format? Like the email validation for example. I would like to have the same for fiscal ID's, etc. Any ideas? Quote Link to comment Share on other sites More sharing options...
Nuke354 Posted April 17, 2020 Report Share Posted April 17, 2020 This links might give you an idea on how it can be done by adding a required pattern attribute to your text fields.https://stackoverflow.com/questions/39343696/jquery-fiscal-code-validationhttps://stackoverflow.com/questions/39592208/dynamically-adding-pattern-and-title-attributes-to-input-control Here's an example that you can test in an HTML Block w/ Header and Footer for the styles: <div>FISCAL ID: <input type="text" name="name" required pattern="[A-Z]{6}\d{2}[A-E,H,L,M,P,R,S,T]{1}\d{2}[A-Z]{1}\d{3}[A-Z]{1}" /></div> <style> input:required:invalid {background-color: lightcoral;} input:required:valid {background-color: lightgreen;} </style> With this knowledge, you can select the Caspio text field and use: .setAttribute("pattern","[A-Z]{6}\\d{2}[A-E,H,L,M,P,R,S,T]{1}\\d{2}[A-Z]{1}\\d{3}[A-Z]{1}"); Quote Link to comment Share on other sites More sharing options...
futurist Posted November 20, 2023 Report Share Posted November 20, 2023 Just to add, if you also wish to validate value entered in an input field to make sure that it follows this format: www.websitename.com Then you can use this code: <script type="text/javascript"> document.addEventListener('BeforeFormSubmit', function(event) { var inputField = document.querySelector('#InsertRecordNameofField'); const value = inputField.value; const regex = /^www\.[a-zA-Z0-9-]+\.[a-zA-Z]{2,}$/; if (!regex.test(value)) { event.preventDefault(); alert('Invalid Submission!'); } else { document.form["caspioform"].submit(); } }); </script> Make sure to replace "NameofField" with the actual name of the field that you want to validate before submitting. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.