generated from ayushsoni1010/next-chakra-ui-template
-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added helper file for toast and email validation
- Loading branch information
1 parent
ac09dd1
commit 70f5d58
Showing
1 changed file
with
28 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { toast } from "react-toastify"; | ||
|
||
const helpers = { | ||
/***** Hardcoded RegEx for Email validations *****/ | ||
validEmail: (email) => { | ||
let valid = | ||
/^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; | ||
|
||
let specials = /[*|\":<>[\]{}`\\()';&$]/; | ||
|
||
return valid.test(email) && !specials.test(email); | ||
}, | ||
|
||
/***** Toast for Base Error Messages by using React Toastify library *****/ | ||
alertToastHandling: (message, position = "top-right") => { | ||
toast(message, { | ||
position: "top-right" || position, | ||
autoClose: 5000, | ||
hideProgressBar: false, | ||
closeOnClick: true, | ||
pauseOnHover: true, | ||
draggable: true, | ||
progress: undefined, | ||
}); | ||
}, | ||
}; | ||
|
||
export { helpers }; |