SoFunction
Updated on 2025-02-28

Explanation of test function of js regular expression


<html>
<script language="javascript" type="text/javascript">
/*Designed By Androidyue*/
/*
Function: Detect the legality of the email address
*/
function checkEmail(){
//Get the information entered by the user in the text box
var objStr=("email").value;
//Set regular expressions that match email
var objReg=//w+[@]{1}/w+[.]/w+/;
//(objStr);
//If you determine whether there is matching content in the string, if there is a prompt correct information, otherwise an error will be returned
if((objStr)){
alert("This email address is legal!");
}else{
alert("This email address is illegal!");
}
}
</script>
<body>
Please enter the email address:
<input type="text" ><!--Set Email input box-->
<input type="button" value="detect legality" onclick="checkEmail()"><!--Set the button to start to detect email legality events-->
</body>
</html>