例如,在文本输入中输入邮箱时,它应该验证并显示错误消息.输入的邮箱是否有效

enter image description here

推荐答案

可以使用正则表达式判断输入的邮件是否有效.

Regex function

validateEmail = (email) => {
  var re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
    return re.test(email);
};

Submit text input function

onSubmit = () => {
if (!this.validateEmail(this.state.text_input_email)) {
  // not a valid email
} else {
  // valid email
}

React-native相关问答推荐

没有给出相同价值观的时刻

嵌套的FlatList内的Incorrect Padding

你使用 react native 应该学习 react.js 吗?

React 从 babel 6 到 babel 7 的原生升级

react-native StyleSheet 属性和选项列表

'React native run android' 在模拟器中启动应用程序后立即停止

请求无法完成,因为您已超出配额

错误:看起来您在另一个中嵌套了一个NavigationContainer

TypeError:undefined is not an object(判断'navigator.geolocation.requestAuthorization')

如何在 React Navigation createStackNavigator 中更改字体系列

如何将抖动动画添加到视图(react-native)?

redux-observable Promise 在单元测试中没有得到解决

Typescript:onPress 类型

如何在 React Native 中使用 index.js 而不是 (index.ios.js, index.android.js) 进行跨平台应用程序?

如何将 BuildConfig 值传递给依赖模块?

Unexpected token on "export default const"

您将如何在 Alert 中模拟onPress?

对未计算文件的本机Bundle sha-1 做出react(无法从assets index.android.bundle 加载脚本)

如何在 React Native 中禁用图像淡入效果?

React Native,更改 React Navigation 标题样式