如何在 React Native 中的 @ 符号之前设置最小字符数限制
How can I set minimum characters limit before @ symbol in React Native
这就是我在 React Native 注册页面中设置错误的方式。问题是它正在检查整个电子邮件长度,但我需要在 @ 符号之前施加 3 个字符限制。执行此操作的最佳方法是什么?
我正在使用 Native Base 作为我的 UI 套件
const validate = () => {
let errors = {};
if (!formData.firstName) errors.firstName = "First name is required";
if (!formData.lastName) errors.lastName = "Last name is required";
if (!formData.email) errors.email = "Email is required";
if (formData.email && formData.email.length < 3) errors.email = "Email is must be 3 characters";
if (!formData.password) errors.password = "Password is required";
if (!formData.confirmPassword)
errors.confirmPassword = "Confirm password is required";
if (formData.password !== formData.confirmPassword)
errors.confirmPassword = "Passwords do not match";
setErrors(errors);
return Object.keys(errors).length === 0;
};
您可以按如下方式使用 split
函数。
if (formData.email && formData.email.includes('@') && formData.email.split('@')[0].length < 3)
这就是我在 React Native 注册页面中设置错误的方式。问题是它正在检查整个电子邮件长度,但我需要在 @ 符号之前施加 3 个字符限制。执行此操作的最佳方法是什么?
我正在使用 Native Base 作为我的 UI 套件
const validate = () => {
let errors = {};
if (!formData.firstName) errors.firstName = "First name is required";
if (!formData.lastName) errors.lastName = "Last name is required";
if (!formData.email) errors.email = "Email is required";
if (formData.email && formData.email.length < 3) errors.email = "Email is must be 3 characters";
if (!formData.password) errors.password = "Password is required";
if (!formData.confirmPassword)
errors.confirmPassword = "Confirm password is required";
if (formData.password !== formData.confirmPassword)
errors.confirmPassword = "Passwords do not match";
setErrors(errors);
return Object.keys(errors).length === 0;
};
您可以按如下方式使用 split
函数。
if (formData.email && formData.email.includes('@') && formData.email.split('@')[0].length < 3)