Java Common Regular Expression validation

Source: Internet
Author: User
public class Regex {
2
3/**
4 * Check the email input is correct
5 * Correct writing format for username@domain
6 * @param value
7 * @return
8 */
9 public boolean Checkemail (String value, int length) {
Ten return Value.matches ("\\w+ [-+.] \\w+) *@\\w+ ([-.] \\w+) *\\.\\w+ ([-.] \\w+) * ") &&value.length () <= length;
11}
12
13/**
14 * Check the telephone input is correct
15 * Correct format 012-87654321, 0123-87654321, 0123-7654321
@param value
* @return
18 */
public boolean Checktel (String value) {
Return Value.matches ("\\d{4}-\\d{8}|\\d{4}-\\d{7}|\\d (3)-\\d (8)");
21}
22
23/**
24 * Check the phone input is correct
25 *
* @param value
* @return
28 */
public boolean checkmobile (String value) {
Return Value.matches ("^[1][3,5]+\\d{9}");
31}
32
33/**
34 * Check Chinese name input is correct
35 *
@param value
Panax Notoginseng * @return
38 */
Checkchinesename Boolean (String value, int length) {
Return value.matches ("^[\u4e00-\u9fa5]+$") &&value.length () <= length;
41}
42/**
43 * Check HTML in the empty line or space
@param value
* @return
46 */
The public boolean Checkblank (String value) {
Value.matches return ("^\\s*|\\s*$");
49}
50/**
51 * Check whether the string contains HTML tags
* @param value
* @return
54 */
55
The public boolean Checkhtmltag (String value) {
Value.matches ("< \\s*?) [^>]*>.*?</\\1>|<.*? /> ");
58}
59/**
60 * Check the URL is legal
* @param value
* @return
63 */
The public boolean checkurl (String value) {
Value.matches return ("[a-za-z]+://[^\\s]*");
66

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.