We help IT Professionals succeed at work.

Regular express validation

IT Genesis
IT Genesis asked
on
I need validation expression only Arabic character and Three names
Comment
Watch Question

Terry WoodsIT Guru
Most Valuable Expert 2011

Commented:
What do you mean by three names?

Do you mean you want to match?
Charles William Harry

Open in new window

but not
Bernie Donald

Open in new window

Author

Commented:
yes two spaces i try to use thtis \w+ \w+ but not work
Terry WoodsIT Guru
Most Valuable Expert 2011

Commented:
When using a pattern for validation purposes, you usually need to add start and end of string placeholders (^ and $) to ensure no additional characters exist before or after the characters matched by the pattern.

eg the pattern ab?d would match the value abcde but pattern ^ab?d$ would not match it.

So for 3 words separated by a space character you might want to try pattern:
^\w+ \w+ \w+$

Open in new window

Author

Commented:
yes but it run with English  character only no different  language
Terry WoodsIT Guru
Most Valuable Expert 2011

Commented:
Then you could use this:
^[a-zA-Z]+ [a-zA-Z]+ [a-zA-Z]+$

Open in new window

Or the same thing, but shorter:
^([a-zA-Z]+ ){2}[a-zA-Z]+$

Open in new window

Author

Commented:
it also work with English letter
Terry WoodsIT Guru
Most Valuable Expert 2011

Commented:
Sorry, you'll need to better explain what the problem is.
Commented:
I Solve my problem with that Expression


"^[\u0621-\u064A\040]+ [\u0621-\u064A\040]+ [\u0621-\u064A\040]+$"

Open in new window


this that I mean
<asp:RegularExpressionValidator ID="RegularExpressionValidator3" runat="server" ErrorMessage="ادخل الاسم ثلاثي" ControlToValidate="Txt_name" ValidationExpression="^[\u0621-\u064A\040]+ [\u0621-\u064A\040]+ [\u0621-\u064A\040]+$"></asp:RegularExpressionValidator>  

validation accept only Arabic letter  and three names

Author

Commented:
@Terry Woods

Thanks for your help