Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use regular expressions in ExtJS

2025-01-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

How can regular expressions be used in ExtJS? In view of this problem, this article introduces the corresponding analysis and answers in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible way.

The copy code is as follows:

Ext.onReady (function () {

Ext.QuickTips.init ()

});

The verification properties of ExtJS's Regex are divided into two cases, one is that there is only a red prompt box; the other is that a note-like prompt appears next to the prompt box, but add Ext.QuickTips.init () when the page is loaded; the prompt box can be displayed normally.

Special hint: use / ^ add regular $/ to wrap the above regular expression after the attribute regex, otherwise it will report "missing object".

Example:

The copy code is as follows:

{

Xtype:'textfield'

FieldLabel: 'postal code'

Name:'postCode'

Regex: / ^ [1-9]\ d {5} (?!\ d) $/

RegexText: 'please enter the correct zip code'

Anchor:'90%'

}

Regular expressions that match Chinese characters: [\ u4e00 -\ u9fa5]

Note: matching Chinese is really a headache. It's easy to have this expression.

Match double-byte characters (including Chinese characters): [^\ X00 -\ xff]

Note: can be used to calculate the length of a string (a double-byte character length meter 2 ~ ~ ASCII character counter 1)

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

Comment: can be used to delete blank lines

Regular expression that matches the HTML tag:] * >. *? |

Commentary: the version circulated on the Internet is too bad, the above one can only match part of it, and there is still nothing I can do about complex nested tags.

Regular expression that matches the leading and trailing white space characters: ^\ s* |\ sblank $

Comment: a very useful expression that can be used to delete white space characters (including spaces, tabs, page feeds, etc.) at the beginning and end of a line

The regular expression that matches the Email address:\ W + ([- +.]\ w +) * @\ w + ([-.]\ w +) *.\ w + ([-.]\ w +) *

Comment: form validation is very useful

Regular expression that matches the URL URL: [a-zA-z] +: / / [^\ s] *

Note: the function of the version circulated on the Internet is very limited, and the above version can basically meet the needs.

Whether the matching account is legal (5-16 bytes are allowed at the beginning of the letter, and alphanumeric underscores are allowed): ^ [a-zA-Z] [a-zA-Z0-9 _] {4j 15} $

Comment: form validation is very useful

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

Commentary: matching forms such as 0511-4405222 or 021-87888822

Match Tencent QQ number: [1-9] [0-9] {4,}

Commentary: Tencent QQ starts from 10000

Match the postcode of China: [1-9]\ d {5} (?!\ d)

Commentary: the postal code of China is 6 digits

Match ID:\ d {15} |\ d {18}

Commentary: Chinese ID cards are 15 or 18 digits

Match ip address:\ d +\.\ d +\.\ d +

Note: useful when extracting ip addresses

Match specific numbers:

^ [1-9]\ positive integer matching $/ /

^-[1-9]\ negative integer matching $/ /

^ -? [1-9]\ match integer

^ [1-9]\ d* | 0 $/ / matches a non-negative integer (positive integer + 0)

^-[1-9]\ d* | 0 $/ / matches non-positive integers (negative integers + 0)

^ [1-9]\ d *\.\ d * | 0\.\ d * [1-9]\ dfloat $/ / matches positive floating point numbers

^-([1-9]\ d *.\ d * | 0.\ d * [1-9]\ d *) $/ / matches negative floating point numbers

^ -? ([1-9]\ d *.\ d * | 0\.\ d * [1-9]\ d * | 0?\ .0 + | 0) $/ / match floating point number

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

^ (- ([1-9]\ d *\.\ d * | 0\.\ d * [1-9]\ d *)) | 0?\ .0 + | 0 $/ / matches non-positive floating point numbers (negative floating point + 0)

Commentary: useful when dealing with a large amount of data, pay attention to corrections in specific applications

Match a specific string:

^ [A-Za-z] + $/ / matches a string of 26 English letters

^ [Amurz] + $/ / matches a string of 26 English letters in uppercase

^ [amurz] + $/ / matches a string of 26 lowercase letters

^ [A-Za-z0-9] + $/ / matches a string of numbers and 26 letters

^\ w match $/ / match a string consisting of numbers, 26 letters, or underscores

Commentary: some of the most basic and most commonly used expressions

This is the answer to the question about how to use regular expressions in ExtJS. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel for more related knowledge.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 278

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report