Home  • Programming • JavaScript

Basic Email Validation with JavaScript

learning javascript
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    Email: <input type="text" id="txtData" /><span id="msg"></span>
    <button onclick="checkEmail()">Check Data</button>
    <script>
        function checkEmail(){
            let email=document.getElementById("txtData").value;
           
            let rex=/^[a-zA-Z0-9]+[@][a-zA-Z0-9]+[.][a-zA-Z]{2,3}$/
            
            let ok=rex.test(email); 
            if(ok==true){
                document.getElementById("msg").innerHTML="Ok";
            }else{
                document.getElementById("msg").innerHTML="Error";
            }
        }
    </script>
</body>
</html>

Comments 0


Copyright © 2024. Powered by Intellect Software Ltd