osmanedip
osmanedip

Reputation: 77

JSF <f:validateRegex pattern

I cant understand this:

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

please someone explain for me

Upvotes: 0

Views: 3328

Answers (1)

Paul Samsotha
Paul Samsotha

Reputation: 208994

((\(\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

Upvotes: 2

Related Questions