
Hi,
I want to know how to check a text value is numeric or not when user enters the text to the textbox.After checking whether the enter text is numeric we need to display in LwDialog showing proper message. Regards Nibedita

Hi Friend,
Try this:
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.util.regex.*;
public class CheckTextFieldValue extends Frame{
CheckTextFieldValue(){
Label lab=new Label("Enter Numeric Value: ");
final TextField text=new TextField(20);
Button b=new Button("Check");
lab.setBounds(20,50,150,20);
text.setBounds(180,50,150,20);
b.setBounds(180,80,80,20);
setLayout(null);
add(lab);
add(text);
add(b);
setSize(350,130);
setVisible(true);
b.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
String input=text.getText();
Pattern p = Pattern.compile("[A-Z,a-z,&%$#@!()*^]");
Matcher m = p.matcher(input);
if (m.find()){
JOptionPane.showMessageDialog(null,"Invalid Number!\nYou must enter only digits between 0 and 9","Error",JOptionPane.ERROR_MESSAGE);
text.setText("");
}
}
});
}
public static void main(String[] args){
new CheckTextFieldValue();
}
}
Thank
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.