Regular Expression for alphabets with spaces

前端 未结 8 1917
庸人自扰
庸人自扰 2020-12-13 18:34

I need help with regular expression. I need a expression which allows only alphabets with space for ex. college name.

I am using :

var regex = /^[a-         


        
相关标签:
8条回答
  • 2020-12-13 18:35

    This will work for not allowing spaces at beginning and accepts characters, numbers, and special characters

    /(^\w+)\s?/
    
    0 讨论(0)
  • 2020-12-13 18:42

    This will allow space between the characters and not allow numbers or special characters. It will also not allow the space at the start and end.

    [a-zA-Z][a-zA-Z ]+[a-zA-Z]$
    
    0 讨论(0)
  • 2020-12-13 18:44
    • Special Characters & digits Are Not Allowed.
    • Spaces are only allowed between two words.
    • Only one space is allowed between two words.
    • Spaces at the start or at the end are consider to be invalid.
    • Single word name is also valid : ^[a-zA-z]+([\s][a-zA-Z]+)*$
    • Single word name is in-valid : ^[a-zA-z]+([\s][a-zA-Z]+)+$
    0 讨论(0)
  • 2020-12-13 18:47

    Regular expression starting with lower case or upper case alphabets but not with space and can have space in between the alphabets is following.

    /^[a-zA-Z][a-zA-Z ]*$/
    
    0 讨论(0)
  • 2020-12-13 18:49

    This worked for me

    /[^a-zA-Z, ]/
    
    0 讨论(0)
  • 2020-12-13 18:51

    Just add the space to the [ ] :

    var regex = /^[a-zA-Z ]*$/;
    
    0 讨论(0)
提交回复
热议问题