diff --git a/public/css/main.css b/public/css/main.css index 52ca4224ffcfae406e989749125856aa9be067f2..2d27e8e53b501e3464f156464cc2993aa5209b29 100644 --- a/public/css/main.css +++ b/public/css/main.css @@ -2344,6 +2344,11 @@ div.tooltip { margin-right: 3em; } +.invalid-input { + font-size: 0.875rem; + color: red; +} + /* Admin pannel css starts */ .admin-pannel { diff --git a/src/components/form/fields/Input.js b/src/components/form/fields/Input.js index 58b1b2989debbb71c405354867744c2dc0696f6f..e1c6a629b6f200d68a5739156aa0913e81919afd 100644 --- a/src/components/form/fields/Input.js +++ b/src/components/form/fields/Input.js @@ -12,7 +12,9 @@ class Input extends Component { this.state = { fieldType: "", language: "en", + isInvalid: false, }; + this.validateEmailInput = this.validateEmailInput.bind(this); } componentDidMount() { @@ -34,6 +36,21 @@ class Input extends Component { } } + validateEmailInput = (e) => { + let inputData = e.target.value; + //eslint-disable-next-line + let allowedFormat = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/; + if (inputData.match(allowedFormat)) { + this.setState({ + isInvalid: false, + }); + } else { + this.setState({ + isInvalid: true, + }); + } + }; + render() { // console.log(this.props.field.fieldType); // strings.setLanguage( @@ -54,20 +71,40 @@ class Input extends Component { </span> )} </label> - - <input - type={ - this.props.field.fieldType === - LANG.FIELD_TYPES.numeric - ? "number" - : this.state.fieldType - } - id={"field-" + this.props.field.order} - name={"field_" + this.props.field.order} - className="form-control" - placeholder="Type here" - autoComplete="off" - /> + + {this.props.field.fieldType !== + LANG.FIELD_TYPES.email.toLowerCase() && ( + <input + type={ + this.props.field.fieldType === LANG.FIELD_TYPES.numeric + ? "number" + : this.state.fieldType + } + id={"field-" + this.props.field.order} + name={"field_" + this.props.field.order} + className="form-control" + placeholder="Type here" + autoComplete="off" + /> + )} + + {this.props.field.fieldType === + LANG.FIELD_TYPES.email.toLowerCase() && ( + <div className=""> + <input + type="email" + id={"field-" + this.props.field.order} + name={"field_" + this.props.field.order} + className="form-control" + placeholder="Type here" + autoComplete="off" + onChange={this.validateEmailInput} + /> + {this.state.isInvalid && ( + <p className="invalid-input">Invalid email!</p> + )} + </div> + )} </div> </div> );