- Web templates
- E-commerce Templates
- CMS & Blog Templates
- Facebook Templates
- Website Builders
JS Animated. How to deal with validation of special characters in contact form rd-mailform
January 21, 2016
This tutorial is going to show you how to add special characters to the validation patterns for the contact form rd-mailform in JS Animated templates.
JS Animated. How to deal with validation of special characters in contact form rd-mailformIn order to add special characters to the validation patterns, you need to do the following steps:
-
Open up the js/mailform/jquery.rd-mailform.min.js file using your favorite code editor.
-
Locate the constraints array on line 71. There are 7 validation strategies: LettersOnly, NumbersOnly, NotEmpty, Email, Phone, Date, SelectRequired. Validation patterns are defined by the rule variable:
-
If you need to add special characters to the LettersOnly stategy, you need to insert them inside the square brackets of the rule pattern. For example, let’s add the character 人. Here is the original validation rule:
rule: "^([a-zA-Zа-яА-ЯіїёІЇЁєЄҐґ\\s]{0,})$",
This is the rule after inserting the character 人:
rule: "^([人a-zA-Zа-яА-ЯіїёІЇЁєЄҐґ\\s]{0,})$",
-
Save the changes to the jquery.rd-mailform.min.js file. Make sure you save the file with the UTF-8 encoding.
-
Now if you include the 人 to the “Your Name” field, the script will consider it valid:
- This way you can insert any character or a sequence of characters. You can also look up in the Internet to find a specific validation pattern for your language, which will include all characters. When submitting a search query you need to write it as “validation pattern for Arabic characters”. You can also visit this website. It will help you create a unicode regex for many languages.
Feel free to check the detailed video tutorial below:
JS Animated. How to deal with validation of special characters in contact form rd-mailform