Regular Expressions registered by JSP users

Source: Internet
Author: User

/* Private String username; the user name cannot be blank, and it must be a 3-8 character abcdABcdprivate String password; the password cannot be blank, and it must be a 3-8 number private String password2; the two passwords must be consistent with the private String email; they can be empty. If they are not empty, they must be a valid mailbox private String birthday. If they are not empty, if a valid date **/public boolean validate () {boolean isOk = true; if (this. username = null | this. username. trim (). equals ("") {isOk = false; errors. put ("username", "user name cannot be blank !! ");} Else {if (! This. username. matches ("[a-zA-Z] {3, 8}") {isOk = false; errors. put ("username", "the user name must be 3-8 letters !! ") ;}} If (this. password = null | this. password. trim (). equals ("") {isOk = false; errors. put ("password", "the password cannot be blank !! ");} Else {if (! This. password. matches ("\ d {3, 8}") {isOk = false; errors. put ("password", "the password must be a 3-8 digit number !! ") ;}// Private String password2; the two passwords must be consistent if (this. password2! = Null) {if (! This. password2.equals (this. password) {isOk = false; errors. put ("password2", "The two passwords are inconsistent !! ") ;}} // Private String email; it can be blank. if it is not blank, it is a legal email if (this. email! = Null) {// the email address Regular Expression if (! This. email. matches ("^ ([a-z0-9A-Z] + [-| \.]?) + [A-z0-9A-Z] @ ([a-z0-9A-Z] + (-[a-z0-9A-Z] + )? \\.) + [A-zA-Z] {2,} $ ") {isOk = false; errors. put ("email", "email is not a legal email !! ") ;}} // The regular expression of the mobile phone number is ^ (13 [0-9]) | (15 [^ 4, \ D]) | (18 [-9]) \ d {8} $ // private String birthday; it can be blank, if a valid date if (this. birthday! = Null) {try {DateLocaleConverter conver = new DateLocaleConverter (); conver. convert (this. birthday);} catch (Exception e) {isOk = false; errors. put ("birthday", "birthday must be a date !! ") ;}} Return isOk ;}

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.