Skip to content
This repository has been archived by the owner on Aug 5, 2023. It is now read-only.

Commit

Permalink
Fixed bug that did not allow phone numbers to be correctly validated
Browse files Browse the repository at this point in the history
  • Loading branch information
jusexton committed Jun 18, 2020
1 parent 719b14a commit d60681e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# 0.6.2-alpha

- Fixed bug that didnt allow scroll position to be at top of screen after navigating to a different location.
- Fixed bug that did not allow phone number to be correctly validated

# 0.6.1-alpha

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,21 @@ import { useSelector } from 'react-redux'
import * as Yup from 'yup'
import { ContactForm } from '../ContactForm'

Yup.addMethod(Yup.string, 'phone', function () {
return this.test({
name: 'phone',
message: 'phone must be a valid phone number',
test: (phone = '') => {
const phoneNumberRegex = /^(\+?\d{0,4})?\s?-?\s?(\(?\d{3}\)?)\s?-?\s?(\(?\d{3}\)?)\s?-?\s?(\(?\d{4}\)?)?$/
return phone === '' || phoneNumberRegex.test(phone)
}
})
})

const contactSchema = Yup.object().shape({
name: Yup.string().required(),
email: Yup.string().email().required(),
phone: Yup.string(),
phone: Yup.string().phone(),
reason: Yup.string().required(),
message: Yup.string().min(100).max(2000).required()
})
Expand Down

0 comments on commit d60681e

Please sign in to comment.