简体   繁体   中英

How to generate Regular Expression that doesn't contain any white space at all and even at the beginning or the end of the string

I tried this but it doesn't work : Demo Link

<form name="myform1">
  valid? {{ myform1.$valid }}
  <input type="text" name="username1" ng-model="username1" ng-pattern="/^\S.*?\S$/" required/> ng-pattern="/[a-zA-Z0-9^ ]/"<br />
</form>

You can use

^\S*\S+\S*$

It will detect whitespace between string. You can remove starting and ending whitespace by

$scope.username1.trim();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM