ITeye博客

验证密码必须由字母和数组组成并且长度是6-30位

kirenenko04 · 2014-12-16 15:39 · php · Magento · 编程语言 · Markdown

public function checkPassword($pwd) {
    	if (strlen($pwd)>30 || strlen($pwd)<6)
    	{
    		return array('status'=>false,'msg'=>$this->__('The length of password must be 6 to 30.'));
    	}
    	
    	if(preg_match("/^\d*$/",$pwd))
    	{
    		return array('status'=>false,'msg'=>$this->__('Password must contain letters.'));
    	}
    	 
    	if(preg_match("/^[a-z]*$/i",$pwd))
    	{
    		return array('status'=>false,'msg'=>$this->__('Passwords must contain Numbers.'));
    	}
    	 
    	if(!preg_match("/^[a-z\d]*$/i",$pwd))
    	{
    		return array('status'=>false,'msg'=>$this->__('Password can only contain Numbers and letters.'));		
    	}
    	return array('status'=>true,'msg'=>$this->__('right!'));
    }

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。