10/10/2018, 09:35

có ai biết về cách kiểm tra tính hợp lệ của email bằng Javascript ko?

Chào các bạn!
Có bạn nào biết về biểu thức chính quy để kiểm tra tính hợp lệ một địa chỉ email ko?nếu có thì chỉ cho mình cách sử dụng luôn,thanks a lot!
snoob viết 11:50 ngày 10/10/2018
Tớ thì gà js lắm, chỉ biết xài jquery thôi , nêú cậu biết xài jquery thì xài thêm plugin này còn không thì ráng học jquery vậy, dễ lắm, lâu nay toàn jquery cả ít khi này động đến javascript lắm.
conmeocattai viết 11:48 ngày 10/10/2018
File JS

Code:
<script language = "Javascript">

function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail ID")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail ID")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

 		 return true					
	}

function ValidateForm(){
	var emailID=document.frmSample.txtEmail
	
	if ((emailID.value==null)||(emailID.value=="")){
		alert("Please Enter your Email ID")
		emailID.focus()
		return false
	}
	if (echeck(emailID.value)==false){
		emailID.value=""
		emailID.focus()
		return false
	}
	return true
 }
</script>
Ở HTML :

Code:
<form name="frmSample" method="post" action="#" onSubmit="return ValidateForm()">
                <p>Enter an Email Address : 
                  <input type="text" name="txtEmail">
                </p>
                <p> 
                  <input type="submit" name="Submit" value="Submit">
                </p>
              </form>
duongdangquoc viết 11:46 ngày 10/10/2018
Được gửi bởi snoob
Tớ thì gà js lắm, chỉ biết xài jquery thôi , nêú cậu biết xài jquery thì xài thêm plugin này còn không thì ráng học jquery vậy, dễ lắm, lâu nay toàn jquery cả ít khi này động đến javascript lắm.
vậy nhờ bro jquery giúp em câu này với.
http://www.ddth.com/showthread.php?t=273182
temp2 viết 11:37 ngày 10/10/2018
các ứng dụng JavaScript liên quan đến email
levanphong7887 viết 11:48 ngày 10/10/2018
Thanks các bạn đã trả lời,nhưng cái mình cần la biểu thức chính quy kìa.ai biết thì chỉ dùm,thanks nhiều.
dinhanhency viết 11:45 ngày 10/10/2018
Được gửi bởi levanphong7887
Thanks các bạn đã trả lời,nhưng cái mình cần la biểu thức chính quy kìa.ai biết thì chỉ dùm,thanks nhiều.
Không hiểu bạn này đang muốn gì nữa.
conmeocattai đã reply về hàm check tính hợp lệ của 1 địa chỉ email
snoob viết 11:36 ngày 10/10/2018
Được gửi bởi levanphong7887
Thanks các bạn đã trả lời,nhưng cái mình cần la biểu thức chính quy kìa.ai biết thì chỉ dùm,thanks nhiều.
Ok, nó đây click here
huynhtronghoan viết 11:46 ngày 10/10/2018
Chac cai nay la chinh quy ah
function isValidEmail(strEmail)
{
validRegExp = /^[^@]+@[^@]+.[a-z]{2,}$/i;
if (strEmail.search(validRegExp) == -1)
return false;
return true;
}
http://rapid-dev.net/2009/04/javascr...ar-expression/
Bài liên quan
0