简体   繁体   English

如何生成不包含任何空格的正则表达式,甚至在字符串的开头或结尾也不包含任何空格

[英]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();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在正则表达式的开头和结尾删除空格? - how to remove white space at the beginning and end of a regular expression? 字符串开头和结尾没有空格 - No white space in the beginning and at the end of string 正则表达式在开始时将任何字符与特定字符串匹配 - Regular expression match any character at the beginning end with specific string 在字符串的开头和结尾添加空格 - Add white space in the beginning and the end of a string 正则表达式 - 字符串无法启动,以空格结尾并且由一行中的少量空格组成 - Regular expression - String cannot start, end with white-space and consist of few white-spaces in a row 如何仅使用正则表达式匹配不包含特定单词的字符串范围? - How to match a range of string that doesn't contain an specific word using only regular expression? 如何在Javascript中的正则表达式中添加空格 - How to add white space in regular expression in Javascript 正则表达式是否可以匹配字符串开头或结尾的字符(但不能同时匹配)? - Can a regular expression match a character at the beginning OR end of the string (but not both)? 用于检查字符串的正则表达式,必须包含空格并且是字母数字 - Regular expression for checking a string, which must contain a space and be alpha numeric 删除LINES开头和结尾的空白 - Remove white space from beginning and end of LINES
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM