We are moved to new domain
Click -> www.ehowtonow.com
Friday, 10 March 2017

Validate Password using Java Regular Expression

Password Regular Expression Pattern
((?=.*\\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[@#^$%!&]).{8,14})
Regular ExpressionDescription


for more regular expression syntax refer Java Regular Expression Syntax Descriptions 

PasswordValidator.java
package com.javatutorialcorner.regex;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class PasswordValidator {
 private static final String PATTERN = "((?=.*\\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[@#^$%!&]).{8,14})";

 public static void main(String[] args) {

  System.out.println("Validate Valid pattern - Abc12@abc : "+validate("Abc12@abc"));
  System.out.println("Validate No Uppercase - JTC123 : "+validate("abc12@abc!"));
  System.out.println("Validate No Upper case No Speacial character - abc1234 : "+validate("abc1234"));
  System.out.println("Validate Less than 8 character - aBc@1! : "+validate("aBc@1!"));
  System.out.println("Validate More than 14 characer @JavaTutorialCornor : "+validate("@JavaTutorialCornor"));

 }

 private static boolean validate(String password) {
  Pattern pattern = Pattern.compile(PATTERN);
  Matcher matcher = pattern.matcher(password);
  return matcher.matches();

 }

}


Output : 

Validate Valid pattern - Abc12@abc : true
Validate No Uppercase - JTC123 : false
Validate No Upper case No Speacial character - abc1234 : false
Validate Less than 8 character - aBc@1! : false
Validate More than 14 characer @JavaTutorialCornor : false

Shop and help us

Flipkart Offer Snapdeal offer Amazon.in offer Amazon.com offer
  • Blogger Comments
  • Facebook Comments
  • Disqus Comments

0 comments:

Post a Comment

Item Reviewed: Validate Password using Java Regular Expression Rating: 5 Reviewed By: eHowToNow