Updated regex pattern, using modifier i to reduce it, looks better now.
This time, it can be considered as Project work round 2, and the mission is do the form valition by JavaScript. Frankly speaking, I don't even have a clear clue about what I am going to do (or if I was able to do anything about that) until some morning - after I read one article from my APP - then the whole thing became clearly enough. And in a awesome and reusable way of course.
UPDATE
Different browsers act differently somehow. eg, input value is “12312” on Chrome and “123 12” on FireFox, so should be more careful! cl cl cl!!!
Got to know that we can use Proxy Pattern instead. article link ⬅ Will read later.
There are actually three parts, and the core is to create encapsulation so that you can reuse this pattern. IIFE is implemented to avoid creating global variables.
1) form-opt.js
2) rule-list.js
3) call these validation patterns
1) create stratege Class
1 | const _validator = (function () { |
2) write your own stratege methods for validation
In my case, here are the code I used
1 | /* rule-list */ |
3) Create an instance and begin our validation with customized errmsg
1 | /* Create instance and pass ruleList*/ |
In the end, keep several functions that can also be reused.
1 | function formatName(nameAreaValue) { |