Hi Friends đź‘‹,

Welcome To Infinitbility! ❤️

To validate email string using regex, use /^(([^<>()[\]\\.,;:\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,}))$/ it will handle date.

This regex will validate string date should passing it to the Date constructor returns a valid Date object.

Let’s see short example of javascript regex for validate email.

const regex = /^(([^<>()[\]\\.,;:\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,}))$/;
console.log(regex.test("[email protected]"))

Today, I’m going to show you How do I check value contain valid date in javascript, as above mentioned, I’m going to use the above-mentioned regex with test() method.

Let’s start today’s tutorial how do you check valid date in javascript using regex?

Here, I will show validate email in javascript and typescript.

Javascript regex for validate email example

Here, we will create common validate function where we will validate param should validate email.

function validate(param){
  const regex = /^(([^<>()[\]\\.,;:\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,}))$/;
  return regex.test(param);
}

// validate email
console.log(validate("[email protected]"))
// true

// validate email without @
console.log(validate("hello.infinitbility.com"))
// false

// validate email without domain extansion
console.log(validate("hello@infinitbility"))
// false

// validate email with country based domain
console.log(validate("[email protected]"))
// true

// validate email without @ before char
console.log(validate("infinitbility.co.in"))
// false

// validate gmail email
console.log(validate("[email protected]"))
// true

Output

Typescript regex for validate email example

Same like javascript, we will create a function and call it with diffrent parameters.

function validate(param: string){
  const regex = /^(([^<>()[\]\\.,;:\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,}))$/;
  return regex.test(param);
}

// validate email
console.log(validate("[email protected]"))
// true

// validate email without @
console.log(validate("hello.infinitbility.com"))
// false

// validate email without domain extansion
console.log(validate("hello@infinitbility"))
// false

// validate email with country based domain
console.log(validate("[email protected]"))
// true

// validate email without @ before char
console.log(validate("infinitbility.co.in"))
// false

// validate gmail email
console.log(validate("[email protected]"))
// true

Output

I hope it helps you, All the best đź‘Ť.