Suggested Videos
Part 48 - Tools for writing regular expressions
Part 49 - JavaScript strings and regular expressions
Part 50 - JavaScript RegExp object
In this video we will discuss, how regular expressions can be used to perform client side validation.
On most of the websites it is common to check if the format of the email is valid. Using regular expressions we can achieve this very easily.
Invalid email :
Valid email :
Here is an example:
Part 48 - Tools for writing regular expressions
Part 49 - JavaScript strings and regular expressions
Part 50 - JavaScript RegExp object
In this video we will discuss, how regular expressions can be used to perform client side validation.
On most of the websites it is common to check if the format of the email is valid. Using regular expressions we can achieve this very easily.
Invalid email :
![javascript validate email regex](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEithbWtOCwVhOfO6x5LXlwE2y0cBjc7jBZRlfrsvA3L5LPK6AnVlPq8DAjDoHMnIJ4AzSuwtiI0xcALdTkaB0jXOFVUlfXpXiaeKo121n4Re0XGv79CiyFWJL3XcUTenOTGZz-d96a_7Dc/s1600/javascript+validate+email+regex.png)
Valid email :
![javascript validate email regular expression](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiz46NyQQwPVaoUb6pDCMlA7GwhCxvVuKUeERkDC17w3ejDAswB5aYdUPzARg3Oeu8FuB5uqHlgxCxUBU2Iyc7BsbCdj90CR8mfasKPWh6fnbgtkNLZIxXD10QfBzx_jXOuLXPuDi3vye8/s1600/javascript+validate+email+regular+expression.png)
Here is an example:
Email : <input type="text" id="txtEmail" onkeyup="validateEmail()" />
<script type="text/javascript">
function validateEmail()
{
var emailTextBox = document.getElementById("txtEmail");
var email = emailTextBox.value;
var emailRegEx = /^(([^<>()[\]\\.,;:\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,}))$/;
emailTextBox.style.color = "white";
if (emailRegEx.test(email))
{
emailTextBox.style.backgroundColor
= "green";
}
else
{
emailTextBox.style.backgroundColor
= "red";
}
}
</script>
![JavaScript tutorial](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj13IEpmfH31PXAmq3AI1T-giJvq7XrMyLstNh5K4kw0zBh30JKTZslb4GwOmCh-CVsS25HBsvnK6QdXemuSpZR1fOBMh9bnqr9bojDBWuIFmmc3h_14f9cLs7DZdoaUpTjtVKJ4NXuwfU/s1600/JavaScript+Tutorial.png)
No comments:
Post a Comment
It would be great if you can help share these free resources