Regular expression that allows spaces in a string, but not only blank spaces

后端 未结 6 2107
长发绾君心
长发绾君心 2020-12-01 18:31

I need to write a regular expression for form validation that allows spaces within a string, but doesn\'t allow only white space.

For example - \'Chicago Heigh

6条回答
  •  我在风中等你
    2020-12-01 19:12

    If we wanted to apply validations only with allowed character set then I tried with USERNAME_REGEX = /^(?:\s*[.\-_]*[a-zA-Z0-9]{1,}[.\-_]*\s*)$/;

    • A string can contain any number of spaces at the beginning or ending or in between but will contain at least one alphanumeric character.
    • Optional ., _ , - characters are also allowed but string must have one alphanumeric character.

提交回复
热议问题