JavaScript: Verify the dynamic data in the input [type = 'text'] Box
The following describes the regular expression components. First, we define an object such as koringz: koringz = function () {}|{}. Second, we will add a method to this koringz object. Currently, it is used to verify the text box of the regular expression. Therefore, I define this method as the REGEXP, an uppercase English letter of the regular expression. Koringz. under REGEXP = function () {}, I want to input three parameters for REGEXP. doc indicates the dom node of the input [type = 'text'] text, reg is the regular expression of the internal value to be matched, and tag is the label of the node that outputs this information (of course, it can also be a class or id. REGEXP = function (doc, reg, tag) {} with the above method, we need to monitor the dynamic data in the event text box in real time. oninput can represent the data listening: koringz. REGEXP = function (doc, reg, tag) {doc. oninput = function () {}} below is the start of the execution of the judgment, when it is null, we can deal with the method: if (this. value = "" | this. value = "undefined") conlose_null_method (ta G) // fun1 () when the output condition is not empty, we can handle the following method: else conlose_match_method (This, reg, tag) // fun2 () the method called by the output method can be written as follows: function conlose_null_method (tag) {tag. innerHTML = "You have not entered! "} Function conlose_match_method (This, reg, span) {if (reg. test (This. value) span. innerHTML =" the input is correct! "Else span. innerHTML =" your input is incorrect! "} Finally, we only need to write the following style call on the html page: Suppose we have a div block:
<Div class = "name"> <label for = "name"> </label> <input type = "text" vlaue = "" placeholder = "Enter name" id = ""name"> <span> * </span> </div>
Then the following js calls the function: <script type = "text/javascript"> var _ name = document. getElementById ("name"); var match_name =/^ [\ u4E00-\ u9FA5] + $/; var span_name = _ name. parentNode. children. item (2); koringz. REGEXP (_ name, match_name, span_name) </script> basically, the above steps have been completed here. If you want to see the details, you can enter here, or you want to see the view point "koringz". If you want to download it, click "koringz.