ExtJS4 text boxes (TextField) methods for validating (Regex) using regular expressions _ regular expressions

Source: Internet
Author: User
Tags html tags

The ExtJS regex's validation attributes are in two cases, one is a red prompt box, and the other is a comment-like message that appears on the Tip box, but adds Ext.QuickTips.init () when the page is loaded, and the prompt box is displayed correctly.

Special Note: After the attribute regex to use/^ here Gazheng then $/the above regular expression wrapping up otherwise will report "the missing object";

Copy Code code as follows:

{
Xtype: ' TextField ',
Fieldlabel: ' Zip code ',
Name: ' Postcode ',
Regex:/^[1-9]\d{5} (?! \d) $/,
Regextext: ' Please enter the correct zip code ',
Anchor: ' 92% '
}
Xtype: ' TextField ',

1.

Regex:/^[\u4e00-\u9fa5]+$/i,
Regextext: "Please input Chinese",

2.

Regex:/^\d+$/,
Regextext: "The phone number can only be a number",

3.

Regex:/^ (http|https|ftp): \/\/([a-z0-9][a-z0-9_-]*) (\.[ a-z0-9][a-z0-9_-]*) +) (:(\d+))? \/?/i,
Regextext: "Please enter a valid URL address",

4.

Regex:/^[-+]? [\d]+$/,
Regextext: ' Please enter the correct integer ',

5.

regex:/^ (?:(? : 25[0-5]|2[0-4][0-9]| [01]? [0-9] [0-9]?) \.) {3} (?: 25[0-5]|2[0-4][0-9]| [01]? [0-9] [0-9]?) $/,
Regextext: ' Please enter the correct IP address '

6.

regex:/^ ((0[1-9]{3})? ( 0[12][0-9])? [-])? \d{6,8}$/,
Regextext: Please enter the correct telephone number, such as: 0920-29392929 '

7.

regex:/(^0?[ 1][35][0-9]{9}$)/,
Regextext: Please enter the correct cell phone number '

8. Please input English letter '

regex:/^[a-za-z]+$/,

9. ID Card number

Regex:/(^\d{15}$) | (^\d{17} ([0-9]| X) $)/,
Regextext: "The input ID number does not conform to the stipulation!" \n15 digit number should be all digits, 18 digits can be the lowest number or X ",

Regular expressions for string processing, form verification, and other occasions, practical and efficient. Some commonly used expressions are collected here to prepare for a rainy-future.

Matching regular expressions for Chinese characters: [\U4E00-\U9FA5]

Commentary: Matching Chinese is really a headache, with this expression will be easy to do

Match Double-byte characters (including Chinese characters): [^\x00-\xff]

Commentary: can be used to compute the length of a string (a double-byte character length meter 2,ascii 1 characters)

A regular expression that matches a blank row: \n\s*\r

Commentary: can be used to delete blank lines

Regular expression:< matching HTML tags (\s*?) [^>]*>.*?| <.*? />

Commentary: The online version is too bad, the above can only match the part of the complex nested tags still powerless

A regular expression that matches the end-end whitespace character: ^\s*|\s*$

Commentary: A useful expression that can be used to delete white-space characters (including spaces, tabs, page breaks, and so on) at the end of a line at the beginning

Regular expression matching an email address: \w+ ([-+.] \w+) *@\w+ ([-.] \w+) *\.\w+ ([-.] \w+) *

Commentary: Form validation is useful

Regular expressions that match URL URLs: [a-za-z]+://[^\s]*

Commentary: Online circulation of the version of the function is very limited, which can meet the basic requirements

Match account number is legal (beginning of letter, allow 5-16 bytes, allow alphanumeric underline): ^[a-za-z][a-za-z0-9_]{4,15}$

Commentary: Form validation is useful

Match domestic phone number: \d{3}-\d{8}|\d{4}-\d{7}

Commentary: Match form such as 0511-4405222 or 021-87888822

Matching Tencent QQ Number: [1-9][0-9]{4,}

Commentary: Tencent QQ number starting from 10000

Match China ZIP Code: [1-9]\d{5} (?! \d)

Commentary: China postal code is 6 digits

Matching ID: \d{15}|\d{18}
Commentary: China's ID card is 15-or 18-digit

Matching IP address: \d+\.\d+\.\d+\.\d+
Commentary: Useful when extracting IP addresses

Match a specific number:

Copy Code code as follows:

^[1-9]\d*$//Matching positive integer
^-[1-9]\d*$//matching negative integers
^-? [1-9]\d*$//matching integer
^[1-9]\d*|0$//matching nonnegative integer (positive integer + 0)
^-[1-9]\d*|0$//matching non positive integer (negative integer + 0)
^[1-9]\d*\.\d*|0\.\d*[1-9]\d*$//matching positive floating-point numbers
^-([1-9]\d*\.\d*|0\.\d*[1-9]\d*) $//matching negative floating-point number
^-? ([1-9]\d*\.\d*|0\.\d*[1-9]\d*|0?\.0+|0) $//matching floating-point number
^[1-9]\d*\.\d*|0\.\d*[1-9]\d*|0?\.0+|0$//matching nonnegative floating-point number (positive floating-point number + 0)
^ (-([1-9]\d*\.\d*|0\.\d*[1-9]\d*)) |0?\.0+|0$//matching non-positive floating-point numbers (negative floating-point number + 0)

Commentary: useful when dealing with large amounts of data, pay attention to corrections when applied

Match a specific string:

Copy Code code as follows:

^[a-za-z]+$//Match a string of 26 English letters
^[a-z]+$//Match a string of 26 uppercase letters
^[a-z]+$//Match string consisting of 26 lowercase letters
^[a-za-z0-9]+$//Match a string of numbers and 26 English letters
^\w+$//Match A string of numbers, 26 English letters, or underscores

Commentary: Some of the most basic and commonly used expressions

Copy Code code as follows:

Ext.onready (function () {
Ext.QuickTips.init ();
});

Here is a description of some of the properties of ExtJS TextField about validation (Regex)

ExtJS's TextField itself has properties and methods for validating input values, which are configured in the config parameter.

1: null value is allowed

Allowblank:boolean

If true, it is allowed or not, and the default is true.

Blanktext:string

If Allowblank is set to true and the value of that TextField is empty, the string of the Blanktext property is displayed to give the error message.

2: Longest character and shortest character

Maxlength:number

The longest character (can be reached)

Maxlengthtext:string

When the longest character is exceeded, a string of the Maxlengthtext property is displayed to give the error message.

Minlength:number

Shortest characters (can be reached)

Minlengthtext:string

When the shortest character is not set, the string of the Minlengthtext property is displayed to give the error message.

3: Regular Expressions

Regex:regexp

Set regular expression, eg:/^[abc]$/

Regextext:string

When an input value violates a regular expression, a string of the Regextext property is displayed to give an error prompt.

You can use the method IsValid (Boolean Preventmark): Boolean to learn whether the input values meet all of the restrictions.

Attention:

There are two kinds of error prompts, one is to add a wavy red line to the bottom of the TextField box, the other is to display the corresponding error hint string, and give a red wavy line.

The latter method requires a call to Ext.QuickTips.init () in order to take effect, by default, only in the previous way.

Sample:

Copy Code code as follows:

Ext.onready (function () {
var _win=new ext.window ({
Title: "Retrieve Password",
width:180,
Layout: "Form",
Labelwidth:60,
items:[{
Xtype: "TextField",
Fieldlabel: "Your Name",
Allowblank:false,
Blanktext: ' name cannot be empty ',
Minlength:2,
Minlengthtext: "Minimum 2 characters in name",
Maxlength:4,
Maxlengthtext: "Name up to 4 characters",
WIDTH:80,
Regex:/^[abc]{2,4}$/,
Regextext: "Just enter ABC"
}],
buttons:[
{
Text: ' Next '
},{
Text: ' Cancel '
}
]
});
Ext.QuickTips.init ();
_win.show ();
});

The above content is small series to introduce the ExtJS4 text box (TextField) using regular expressions to verify (Regex) method, hope to help everyone!

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.