Siddiq Baig
Siddiq Baig

Reputation: 586

Regex validation Allow only Character and space in Asp.net

hello every one i need a validation that can only validate to character and white space.. no mater how much space and character in text-box

i use this regexp validation below. but its only allow one space between two words but don`t allow the third space for third word.

([A-Za-z])+( [A-Za-z]+)

how to allow only characters and spaces in Regexp Validation?

Upvotes: 4

Views: 13477

Answers (3)

Isuru Ilangange
Isuru Ilangange

Reputation: 11

Try this

Regex.IsMatch(inputToValidate, @"^[a-zA-Z\s]+$")

Upvotes: 1

Sabuj Hassan
Sabuj Hassan

Reputation: 39355

Try this:

([A-Za-z])+( [A-Za-z]+)*
                       ^^ here

* means to repeat the group zero or more times. If you need it to be one or more times, then use +. Another thing you can use [ ]+ instead of space to handle one or more consecutive spaces.

Also, if you need, you can use anchor ^ and $ around your regex. Like ^...regex...$

Upvotes: 4

sshashank124
sshashank124

Reputation: 32189

You can do it as:

^([\sA-Za-z]+)$

Demo: http://regex101.com/r/mQ0jN4

Upvotes: 1

Related Questions