Adnan
Adnan

Reputation: 4607

Add space character to regular expression pattern [a-zA-Z]*

I'm using <f:validateRegex pattern="[a-zA-Z]*"/> for ensuring that entered values contain alphabet only, it is working fine but it is not allowing to take space in the string.
How can i incorporate space character in above pattern? Thanks in advance.

Upvotes: 5

Views: 31088

Answers (3)

Usama Lakhan
Usama Lakhan

Reputation: 1

This worked for me. It includes spaces in text at the start/ end of words.

/^[a-zA-Z ]+$/

Upvotes: -1

Thanveer
Thanveer

Reputation: 5

I'm used this [a-zA-Z_ ]* its working for me

Upvotes: -3

alex
alex

Reputation: 490263

Simply add the space to the regex.

<f:validateRegex pattern="[a-zA-Z ]*"/>

If you wanted any whitespace, not just space, swap the space with \s.

<f:validateRegex pattern="[a-zA-Z\\s]*"/>

Upvotes: 25

Related Questions