Article introduction of Wulin.com (www.vevb.com): HTML5's super simple form verification method is brought to IE and other old browsers.
Product type: Dynamic effects (dynamic JS, jQuery works)
Work Description: Bring HTML5's super simple form verification method to IE and other old browsers
Production idea: Write a plug-in so that old browsers can also use html5 syntax to express verification. You only need to intercept the submit event at the bottom and use jQuery to trigger the invalid event after discovering that the verification rules are not met. Developers only need to simply bind the invalid event to complete the previously very complex form verification function.
I believe that front-end er who likes new things has tried HTML5's form verification function, which is very powerful. Adding required to <input> becomes a required item.
Write a regular expression in the pattern to force the filled-in format. Here is a demo
<form>
<input placeholder=The underscore of 3-5 digits must be filled with, numerals and letters required pattern=/w{3,5}>
<input type=submit>
</form>
<script src=></script>
<script src=form.html5.js></script>
<script>
$(input).bind(invalid, function(e){
alert (if incorrect, you must fill in the underscore of 3-5 digits, numbers, letters);
return false;
});
$(html).submit(function(e){
if(e.isPropagationStopped()){
return;
}
alert(form submitted successfully);
return false;
});
</script>
Very simple or not? All we need to do is two steps
1. Write the verification rules into regular expressions and put them in the pattern attribute in the input tag.
2.jQuery intercepts the invalid event of input
By completing these two steps, you can complete form verification in a modern browser.
But then how to support old browsers? Just add one line of code
<script src=form.html5.js></script>
At the same time, you also need to download these three files and make sure that the three files are in the same directory.
(The purpose of select.htc has nothing to do with form verification.)
When you have the following situation, you can reply to contact me