我的代码小窝
Java or DotNet

2009年5月31日

/**
    刚写了一则关于密码验证的正则表达式,要求,必须包含数字,必须包含字母,必须包含特殊字符。
   
以下是代码,
 刚开始写博客,还不知道该怎么写才合适,摸索中。
   代码有问题的话,帮我指出来,谢谢。
*/
package mytry;
 
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.swing.JOptionPane;
 
public class C3 {
    public static boolean chkPswd( String str ){
        boolean ret = false;
        Pattern pattern = Pattern.compile("(?=.*[0-9]+)(?=.*[a-zA-Z]+)(?=.*\\W+)");
        Matcher mat = pattern.matcher( str );
        ret = mat.find();
       
        return ret;
    }
    public static void main(String[] args) {
        String InpStr = "";
        for(;;){
            InpStr = JOptionPane.showInputDialog("pls Input a String !", "/*-.+-^~=()'&%$#!@`[]{};:,.<>?_a123");
            if( InpStr==null ) InpStr = "";
            if( f8( InpStr ) ){
                System.out.println("Match !");
            }else{
                System.out.println("not Match !");
            }
            if( JOptionPane.showConfirmDialog(null, "Continue ?" )==1 ){
                break;
            }
        }
    }
}

posted @ 2009-05-31 17:57 姜勇 阅读(1005) | 评论 (0)编辑 收藏
仅列出标题