Regex validation Allow only Character and space in Asp.net

12,381

Solution 1

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

Solution 2

Try this

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

Solution 3

You can do it as:

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

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

Share:
12,381
Siddiq Baig
Author by

Siddiq Baig

just think about innovative things

Updated on August 21, 2022

Comments

  • Siddiq Baig
    Siddiq Baig over 1 year

    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?