简体   繁体   中英

JSF <f:validateRegex pattern

I cant understand this:

<f:validateRegex pattern="((\(\d{3}\) ?)|(\d{3}-))?\d{3}-\d{4}" /> 

please someone explain for me

((\\(\\d{3}\\) ?)|(\\d{3}-))?\\d{3}-\\d{4} is a regex for a US phone number, either in the form:

555-555-5555 or (555)555-5555 or 555-5555

First of all \\d means digit.

This part ((\\(\\d{3}\\) ?)|(\\d{3}-))? means (555) or 555- , once or none at all. Broken down its

   (       (\(\d{3}\) ?)            |            (\d{3}-)     )   ?

( (3 digits with () ?- once or no)  |-OR  (three digits plus - ) ) ?-once or none

This part \\d{3}- means 555- (three digits plus -).

This part \\d{4} means 5555 (four digits).

BTW, the 5 's are just placeholders for any digit .

The <f:validateRegex pattern tag and attribute is to validate an input field to match one of the above three patterns.

See more at Regualar Expressions

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM