---
title: "jQuery验证邮箱手机"
author: "xiaotongeye"
date: "2015-06-29T19:03:33Z"
tags: []
categories: ["Web前端"]
slug: "jquery"
draft: false
lastmod: "2015-06-29T19:03:33Z"
id: 2222922
url: "https://xiaotongeye.iteye.com/blog/2222922"
---

验证邮箱：

```js

function checkSignEmail(str){
    		var re = /^(\w-*\.*)+@(\w-?)+(\.\w{2,})+$/
    		if(re.test(str)){
        		return true;
   			 }else{
        		return false;
   					 }
			}

```

例：
```js

$("#show .youxiang_zhuce").focus(function(){
		var v = this.value;
		if(v == "邮箱"){
		$(this).val("");}
		}).blur(
		function(){
			var v = this.value;
			if(v == ""){
				$(this).val("邮箱");
				$("#alert_zhuce").css("display","none");
				$("#show .mima_zhuce").removeAttr("readonly","readonly");
				}
				else{
					checkRegisterEmail(v);
					}
			}
		);

```

验证手机号：

```js

function checkMobile(str) {
    	var re = /^1\d{10}$/
    		if (re.test(str)) {
        		return true;
    		} else {
       			return false;
    			}

```

例：
```js

var number = 18203216051;
	var i = checkMobile(number);

```

密码小于6位：

```js

$("#show .mima_denglu").focus(function(){
		var v = this.value;
		if(v == "密码"){
		$(this).val("");
		$(this).attr("type","password")
		}
		}).blur(
		function(){
			var v = this.value;
			if(v == ""){
				$(this).attr("type","text");
				$(this).val("密码");
				$("#alert2_denglu").css("display","none");
				}
			else if(v.length < 6){
				$("#alert2_denglu").css("display","block");
				}
			else{
				$("#alert2_denglu").css("display","none");
				}
			}
		);

```