DEV Community

Jessica Chappell
Jessica Chappell

Posted on

Javascript Form Regex

Developers often have to validate form inputs both client-side and server-side before storing data in database or displaying UX treatments in the UI.

So here's a helpful list of Javascript regular expressions that you can use for input validation.

Email Regex that works 99% percent of the time

/^(([^<>()\[\]\\.,;:\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,}))$/
Enter fullscreen mode Exit fullscreen mode

Source

Regex for dates in YYYY-MM-DD format

/^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/
Enter fullscreen mode Exit fullscreen mode

Source - See for more date formats

Top comments (0)