-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTextFieldEvent.java
More file actions
64 lines (58 loc) · 2.16 KB
/
Copy pathTextFieldEvent.java
File metadata and controls
64 lines (58 loc) · 2.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package ModelClass;
import java.awt.event.KeyEvent;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.swing.JTextField;
/**
*
* @author AlexJPZ
*/
public class TextFieldEvent {
public void textKeyPress(KeyEvent evt) {
//Declaramos una variable y le asignamos un evento
char car = evt.getKeyChar();
//Condición que nos permite ingresar datos de tipo texto
if ((car < 'a' || car > 'z') && (car < 'A' || car > 'Z')
&& (car != (char) KeyEvent.VK_BACK_SPACE) && (car != (char) KeyEvent.VK_SPACE)) {
evt.consume();
}
}
public void numberKeyPres(KeyEvent evt) {
//Declaramos una variable y le asignamos un evento
char car = evt.getKeyChar();
//Condición que nos permite ingresar datos numéricos con su punto decimal
if ((car < '0' || car > '9') && (car != (char) KeyEvent.VK_BACK_SPACE)) {
evt.consume();
}// else if ((car < '0' || car > '9') && (car != (char) KeyEvent.VK_BACK_SPACE)) {
// evt.consume();
// }
}
public void numberDecimalKeyPress(KeyEvent evt, JTextField textField) {
//Declaramos una variable y le asignamos un evento
char car = evt.getKeyChar();
//Condición que nos permite ingresar datos numéricos con su punto decimal
if ((car < '0' || car > '9') && textField.getText().contains(".")
&& (car != (char) KeyEvent.VK_BACK_SPACE)) {
evt.consume();
} else if ((car < '0' || car > '9') && (car != '.')
&& (car != (char) KeyEvent.VK_BACK_SPACE)) {
evt.consume();
}
}
public boolean isEmail(String correo) {
Pattern pat = null;
Matcher mat = null;
pat = Pattern.compile("^[\\w\\-\\_\\+]+(\\.[\\w\\-\\_]+)*@([A-Za-z0-9-]+\\.)+[A-Za-z]{2,4}$");
mat = pat.matcher(correo);
if (mat.find()) {
return true;
} else {
return false;
}
}
}