Regular Expression for alphabets with spaces

前端 未结 8 1918
庸人自扰
庸人自扰 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:54

    This will accept input with alphabets with spaces in between them but not only spaces. Also it works for taking single character inputs.

    [a-zA-Z]+([\s][a-zA-Z]+)*

    0 讨论(0)
  • 2020-12-13 18:57

    This is the better solution as it forces the input to start with an alphabetic character. The accepted answer is buggy as it does not force the input to start with an alphabetic character.

    [a-zA-Z][a-zA-Z ]+
    
    0 讨论(0)
提交回复
热议问题