The regular expression validation password feature is often used in the project, but a lot of friends still do not use the password regular expression to verify, this article small series for everyone to organize the PHP password verification regular expression, Python password strength is, of course, and everyone commonly used in the JS regular expression, I hope you like.
Just start to review , what is the regular expression?
when you write a program or Web page that handles strings, you often have the need to find strings that meet certain complex rules. Regular expressions are the tools used to describe these rules. In other words, regular expressions are code that records text rules.
php Password validation regular expression (8-bit length limit)
<?php
//password Authentication
$password = "zongzi_abc_oo13a2";
$n = Preg_match_all ("/^[a-za-z\d_]{8,}$/", $password, $array);
Length is 8 or more
var_dump ($array);
? >
Python Password validation Regular expression
#encoding =utf-8 Import re def checklen (pwd): Return len (pwd) >=8 def checkcontainupper (pwd): pattern = Re.compile (' [A -z]+ ') match = Pattern.findall (pwd) if Match:return True else:return False def checkcontainnum (pwd): pattern = Re.
Compile (' [0-9]+ ') match = Pattern.findall (pwd) if Match:return True else:return False def checkcontainlower (pwd): Pattern = Re.compile (' [a-z]+ ') match = Pattern.findall (pwd) if Match:return True else:return False def checksymbol (
PWD): pattern = Re.compile (' ([^a-z0-9a-z]) + ') match = Pattern.findall (pwd) if Match:return True Else:return False def checkpassword (pwd): #判断密码长度是否合法 lenok=checklen (pwd) #判断是否包含大写字母 upperok=checkcontainupper (pwd) #判断是否包含小写字母 lower Ok=checkcontainlower (PWD) #判断是否包含数字 numok=checkcontainnum (pwd) #判断是否包含符号 symbolok=checksymbol (PWD) print (Lenok) prin
T (Upperok) print (Lowerok) print (Numok) print (Symbolok) return (Lenok and Upperok and Lowerok and Numok) def main (): if CheckpasSword (' helloworld#123 '): print (' Detect through ') Else:print (' Detect failed ') if __name__ = = ' __main__ ': Main ()
Java Password Validation Regular expression
/**
* @ClassName: Rextest
* @Description: TODO
* @author BMR
* @date March 28, 2016 a.m. 11:09:17
* * public class Rextest {
/**
* Regular expression authentication password
* @param input
* @return/Public
Static Boolean Rexcheckpassword (String input) {
//6-20-bit, letter, number, character
//string reg = "^" ([a-z]|[ a-z]| [0-9]| [`-=[];,./~!@#$%^*()_+} {:?]) {6,20}$ ";
String regstr = "^" ([a-z]|[ a-z]| [0-9]| [' ~!@#$%^&* () +=| {} ':; ', \\\\[\\\\].<>/?~! @#¥%......&* ()--+| {}【】‘;:”“'。 ,、? ] {6,20}$ ";
Return input.matches (REGSTR);
}
public static void Main (string[] args) {
System.out.println ("Rexcheckpassword is:" + rexcheckpassword ("14 ' ~!@#$%^ &* (\) +=| {}"));
}
Output results:
Rexcheckpassword Is:true
The question that the Netizen raises:
Regular expression checksum password
1, the password must be the number, the character, the special character three kinds of two kinds of composition;
2, password length can not be less than 8 characters;
Meet the above two points, how should be achieved?
(?! ^\\d+$) can't be all numbers.
(?! ^[a-za-z]+$) can't be all letters
(?! ^[_#@]+$) can not be all symbols (only some of the symbols listed here, you can increase yourself, some symbols may need to escape)
. {8,} No less than 8 bits in length
Together is
(?! ^\\d+$) (?! ^[a-za-z]+$) (?! ^[_#@]+$). {8,}
Complete js Regular expression :
Strong: Letters + numbers + special characters ^ (?!) [a-za-z]+$] (?!) \d+$) (?! [!@#$%^&*]+$] (?!) [a-za-z\d]+$] (?!) [a-za-z!@#$%^&*]+$] (?!)
[\d!@#$%^&*]+$) [a-za-z\d!@#$%^&*]+$ /: Letters + numbers, letters + special characters, numbers + special characters ^ (?!) [a-za-z]+$] (?!) \d+$) (?! [!@#$%^&*]+$) [a-za-z\d!@#$%^&*]+$//weak: pure digit, pure letter, pure special character ^ (?: \ d+| [a-za-z]+| [!@#$%^&*]+) $//checksum is all digitally composed function isdigit (s) {var patrn=/^[0-9]{1,20}$/; if (!patrn.exec (s)) return false return True}//Verify logins: You can only enter 5-20 letters beginning with a letter, with numbers, "_", "." String function Isregisterusername (s) {var patrn=/^[a-za-z]{1} ([a-za-z0-9]|[.
_]) {4,19}$/; if (!patrn.exec (s)) return false return True} function Isregisterusername (s) {var patrn=/^[a-za-z]{1} ([a-za-z0-9]|[.
_]) {4,19}$/; if (!patrn.exec (s)) return false return True}//Verify user name: You can enter only 1-30 characters that start with a letter JavaScript code function Istruename (s) {var pa
trn=/^[a-za-z]{1,30}$/; if (!patrn.exec (s)) return false Return True}}//Verify Password: You can enter only 6-20 letters, numbers, underline function ispasswd (s) {var patrn=/^ (\w) {6,20}$/; if (!patrn.exec (s)) return False to return true}//verify ordinary telephone, fax number: You can start with "+", except for numbers, can contain "-" function Istel (s) {//var patrn=/^[+ ]{0,1} (\d) {1,3}[]? ([-]? (\d) {1,12})
+$/; var patrn=/^[+]{0,1} (\d) {1,3}[]? ([-]? ((\d) |
[]) {1,12}) +$/; if (!patrn.exec (s)) return false return True}//Verify mobile phone Number: Must start with a number, except for numbers, can contain "-" function Ismobil (s) {var patrn=/^[+]{0,1 } (\d) {1,3}[]? ([-]? ((\d) |
[]) {1,12}) +$/;
if (!patrn.exec (s)) return false return True}//Verify ZIP code function Ispostalcode (s) {//var patrn=/^[a-za-z0-9]{3,12}$/;
var patrn=/^[a-za-z0-9]{3,12}$/; if (!patrn.exec (s)) return false return True}//Checksum search keyword function Issearch (s) {var patrn=/^[^ ' ~!@#$%^&* () +=|\\\] [\]\{\}:;' \,.<>/?] {1}
[^ ' ~!@$%^& () +=|\\\] [\]\{\}:;' \,.<>?]
{0,19}$/; if (!patrn.exec (s)) return false return True} function IsIP (s)//by zergling {var patrn=/^[0-9.]
{1,20}$/;
if (!patrn.exec (s)) return false return True}
Regular expressions
^\\d+$//non-negative integer (positive integer + 0)
^[0-9]*[1-9][0-9]*$//positive integer
^ (-\\d+) | ( 0+)) $//Non positive integer (negative integer + 0)
^-[0-9]*[1-9][0-9]*$//Negative integer
^-?\\d+$//Integer
^\\d+ (//nonnegative floating-point number (positive floating-point number + 0)
^ ([0-9]+\\. [0-9]*[1-9][0-9]*) | ([0-9]*[1-9][0-9]*\\. [0-9]+) | ([0-9]*[1-9][0-9]*)] $
//Positive float
^ (-\\d+ (//non-positive floating-point number (negative floating-point number + 0)
^ (-) ([0-9]+\\.[ 0-9]*[1-9][0-9]*) | ([0-9]*[1-9][0-9]*\\. [0-9]+) | ([0-9]*[1-9][0-9]*))]
a-z]+$/////////A string consisting of 26 lowercase letters ^[a-za-z0-9]+$///////26 alphanumeric strings
^\\w+$//by numbers, 26 English letters or underscores
^[\\ w-]+ (//email address
^[a-za-z]+://(//url
^[a-za-z0-9_]*$
Regular expression that matches the full domain name:
[a-za-z0-9][-a-za-z0-9]{0,62} (\.[ A-ZA-Z0-9][-A-ZA-Z0-9]{0,62}) +\.?
Friends who want to learn from the system can continue reading: Regular Expressions 30-minute introductory tutorials to further deepen the understanding of regular expressions.
Article 1: The latest mobile phone number, phone number regular expression
The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.