Monday 14, Apr 2025
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

Related Posts:

  • How to make collection read-only Following example shows how to make collection read-only using Collections.unmodifiableSet(collection) method in Java. <String> List<String> java.util.Collections.unmodifiableList(List<? extends String> li… Read More
  • How to get Character unicode point in a StringFollowing example shows how to get unicode point of a character in a String using str.codePointAt(int position) method. Sample Programpackage com.javatutorialcorner.javastring;public class StringUnicode { public static voi… Read More
  • Java Mail API Tutorials This Tutorial contains information about how to send mail using Java mail API, Mail with attachment, HTML mail from Java. Java Mail API - Introduction Sending Simple Email Using Java Mail API Sending HTML Email using Java… Read More
  • How to search a word inside StringFollowing program shows how to search the word inside a string using indexOf(String str) available in Java. The indexOf(String str)  method returns the position of word with in the string if found, otherwise it returns –… Read More
  • How to Create File using Java Following example shows hoe to create file using File() constructor and file.createNewFile() method in Java createNewFile public boolean createNewFile() throws Atomically creates a new, empty file named by this abstract pa… Read More
  • Blogger Comments
  • Facebook Comments
  • Disqus Comments

0 comments:

Post a Comment

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