如何使用正则表达式在字符串中查找空格?

How to find white spaces in a String using regex?

我的注册表中有一个用于密码字段的 EditText。如果用户在密码字段中输入空格,我想显示错误。那么请给出 RegEx 或任何其他解决方案来查找字符串中的任何空格? 谢谢

您可以用作

variable.contains(" ")

或使用正则表达式

Pattern pattern = Pattern.compile("\s");
Matcher matcher = pattern.matcher(s);
boolean found = matcher.find();