首页 > 解决方案 > *%#:& 的正则表达式在本机反应中包括空格?

问题描述

在使用 textBox 做出本机反应时,我需要验证,显示用户是否输入空格或 *%#:& 错误将弹出并突出显示红色文本框。

我的代码 -

_validateInput = (s) => {
  let regSpace = new RegExp(/\s/); // what should i add to check *%#:& currently its checking only white space
  // Check for white space and (*%#:&)
  if (regSpace.test(s)) {
    this.setState({ error: true });
    return false;
  } else {
    this.setState({ error: false });
  }
  return true;
};

标签: react-native

解决方案


你可以试试这个

const name = 'Hi my name is john'
name.replace(/*%#:&\s/g, '') //Himynameisjohn

推荐阅读