JavaScript: Verify the dynamic data in the input [type = 'text'] Box

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.