The JSP page calls the JS file to verify the text box content

Source: Internet
Author: User

Next

3. Check whether the input in the JS verification text box is empty and whether the input is in digital format.

Implementation idea: according to the user's requirements, we need to click the submit button to verify whether all required items are empty and whether some numbers are in numeric format at one time, in addition, the verification prompt should be prompted in a uniform text in one place, and the pop-up window cannot be used. In addition, to avoid repeated work, we want to put all the page prompts in a method of a JS file, so that all the pages only need to call this method to implement the verification function. The final method we use is to judge twice. First, determine whether a control object exists on the page to be verified. If so, determine whether it is null or the format is correct.

Next we will verify the JSCodeShare with you:

// Determine whether the mobile phone number is empty, whether it is a number, and whether it is less than 11 bits var objapplicantcell = Document. getelementbyid ("applicantcell") if (objapplicantcell! = NULL) {var cellnum = document. getelementbyid ("applicantcell "). valueif (cellnum = "") {document. getelementbyid ("flag "). value = "the mobile phone number cannot be blank"; formflag. applicantcell. focus (); Return false;} var STRP =/^ \ D + $/; // If (! STRP. test (cellnum) {document. getelementbyid ("flag "). value = "the mobile phone number is not in digital format"; form1.applicantcell. focus (); Return false;} If (cellnum. length <11) {document. getelementbyid ("flag "). value = "mobile phone number cannot be less than 11 characters"; formflag. applicantcell. focus (); Return false ;}}

This code is used to verify the mobile phone number in one method. Other text boxes can also be used to verify similar writing methods. You can also use this code as a public method to call parameter passing.

Learning Through engineering can not only bring us motivation and interest in learning, but also enhance our self-confidence. With confidence, we will increase our desire to study in depth, in this way, we don't have to worry about any technology that we don't know. As long as you have the motivation to learn, learning technology is just a matter of time.

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.