4

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?

3 Answers 3

4

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...$

Sign up to request clarification or add additional context in comments.

1 Comment

its all my fault how much i am stupid i totally forgot the regex validation syntax but Thanks for explaining. its working
1

You can do it as:

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

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

Comments

1

Try this

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.