有效等价类: 长度:1到6
字符:a-z,A-Z,0-9
无效等价类 长度:0,7
字符:英文/数字以外字符,控制字符,标点符号
部分代码如下:
public void start(Stage stage)throws Exception {
stage.setTitle("TEST");
AnchorPane root = new AnchorPane();
Scene scene = new Scene(root, 500, 300);
scene.setFill(Color.WHITE);
Text usename= new Text("用户名:");
usename.setFont(Font.font ("Serif", 28));
AnchorPane.setTopAnchor(usename, 100.0);
AnchorPane.setLeftAnchor(usename, 50.0);
Text tips= new Text("提示:");
tips.setFont(Font.font ("Serif", 28));
AnchorPane.setTopAnchor(tips, 150.0);
AnchorPane.setLeftAnchor(tips, 50.0);
final TextField textblock=new TextField();
AnchorPane.setTopAnchor(textblock, 105.0);
AnchorPane.setLeftAnchor(textblock, 200.0);
final TextField textblock2=new TextField();
AnchorPane.setTopAnchor(textblock2, 155.0);
AnchorPane.setLeftAnchor(textblock2, 200.0);
Button button = new Button("检验");
AnchorPane.setTopAnchor(button, 105.0);
AnchorPane.setRightAnchor(button, 50.0);
button.setOnAction( new EventHandler<ActionEvent>( ) {
public void handle(ActionEvent actEvt) {
final String input;
input = textblock.getText();
if(input.length() > 6|| input.length() < 1){
textblock2.setText("er1:长度应为1-6");
}
else if(!isRegularRptCode(input,"[a-z,A-Z,0-9]*")){
textblock2.setText("er2: 字符应为a-z,A-Z,0-9");
}
else{
textblock2.setText("OK!!");
}
}
} );
root.getChildren().addAll(usename,tips,textblock,textblock2,button);
stage.setScene(scene);
stage.show();
}
}
结果截图:
原文:http://www.cnblogs.com/wangdongT-T/p/4357912.html