我为React创建了一个FormValidation函数。我使用教程来实现这一点。您可以在上找到一个演示项目。问题是,这个FormValidation在我的项目中不起作用。我也不知道原因。对于我的React,我使用的是常青UI框架。您可以找到TextInputFields (我使用的) 的道具。 浏览0提问于2018-09-18得票数 0 回答已采纳 1回答 使用...
import React, { useState } from 'react'; const EmailValidationForm = () => { const [email, setEmail] = useState(''); const [isValid, setIsValid] = useState(null); const [isChecked, setIsChecked] = useState(false); const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; co...
UserNameValidationThis function alidates name fields, ensuring that the first character is not a whitespace and validate special character. (example:ValidateData.usernameCheck(e.target.value).nameCheck()) emailValidationThis function validates a valid email using regex. (example:ValidateData.email(value...
{// add the rules for validationrules:{'email':{required:[true,'* Enter your email']},'mobile':{required:[true,'* Enter your mobile number']},'name':{required:[true,'* Enter your name']},}};// initialize the form validatorthis.formObject=newFormValidator('#form1',options);}...
$ create-react-app react-form-validation-demo 1. 2. 现在运行程序: $ cd react-form-validation-demo/ $ npm start 1. 2. 程序运行的时候会在http://localhost:3000/打开。 接下来,让我们添加bootstrap,以便我们可以轻松地为表单设置样式: $ npm install react-bootstrap — save ...
errors.email = validEmailRegex.test(value) ? '' : 'Email is not valid!'; break; case 'password': errors.password = value.length < 8 ? 'Password must be 8 characters long!' : ''; break; default: break; } this.setState({errors, [name]: value}, ()=> { ...
num2:PropTypes.number,email:function(myProps,myPropName,myComponentName){if(!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(myProps[myPropName])){returnnewError('Invalid prop value `'+myProps[myPropName]+'` supplied to'+' `'+myComponentName+'/'+myPropName+'`. Validation failed.');}}...
set({ captchaEndpoint: 'simple-captcha-endpoint.ashx' }); } componentDidMount() { let self = this; // the validation-error messages for the form's data-input fields const errorMessages = { name: 'Name must be at least 3 chars long!', email: 'Email is invalid!', subject: 'Subject...
':'';break;case'email':errors.email=validEmailRegex.test(value)?'':'Email is not valid!';break;case'password':errors.password=value.length<8?'Password must be 8 characters long!':'';break;default:break;}this.setState({errors,[name]:value},()=>{console.log(errors)})}...
const message = ({ translate }) => translate('myroot.validation.email_invalid'); const validateEmail = email(message); Per Input Validation: Custom Function ValidatorYou can also define your own validator functions. These functions should return undefined when there is no error, or an error ...