Last active
August 26, 2020 14:13
-
-
Save cpv123/45c117400d620ace29b527390df870b6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Form, Input } from 'antd'; | |
... | |
const validatePhoneNumber = (rule, value, callback) => { | |
const phoneNumberPattern = /\(?([0-9]{3})\)?([ .-]?)([0-9]{3})\2([0-9]{4})/; | |
const isValid = phoneNumberPattern.test(value); | |
if (!isValid) { | |
return callback('Not a valid phone number'); | |
} | |
return callback(); | |
} | |
... | |
<Form.Item | |
name="phoneNumber" | |
label="Phone number" > | |
rules: [ | |
{ | |
required: true, | |
message: 'You must enter a phone number!', | |
}, | |
{ validator: this.validatePhoneNumber }, | |
], | |
> | |
<Input placeholder="Enter a phone number" /> | |
</Form.Item> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment