validating

Ads
 

validating

hi another problem i am facing in swing is that is
i have got many textfeilds
ex:

Roll No:
Name:
Address:

so
Roll No TextField have to Contains only Numbers.
Name TextFields have to contain only Alphabets no special or numbers;
soplz help me how can be validated.

View Answers

March 15, 2010 at 1:08 PM

Hi Friend,

Use the following code if you want to validate textfields TRollNo and TName

TRollNo.addKeyListener(new KeyAdapter() {
public void keyTyped(KeyEvent e) {
String input=TRollNo.getText();
Pattern p = Pattern.compile("[A-Z,a-z,&%$#@!()*^]");
Matcher m = p.matcher(input);
if (m.find()) {
JOptionPane.showMessageDialog(null, "Please enter only numbers");
}
}
});
TName.addKeyListener(new KeyAdapter() {
public void keyTyped(KeyEvent e) {
String input=TName.getText();
Pattern p = Pattern.compile("[0-9]");
Matcher m = p.matcher(input);
if (m.find()){
JOptionPane.showMessageDialog(null,"Enter only characters A-Z or a-z");
}
}
});

Thanks

Ads









Related Tutorials/Questions & Answers:
Validating XML
Validating XML  Hi, I have a string containing data in XML format. I have to Validate this xml data. Is there any method in java that allows strings as input to validate xml?   Please visit the following link: http
validating web pages
validating web pages  How to validate HTML web pages
Advertisements
Validating image size
Validating image size  How to validate image size to 2MB in javascript which is updating to mysql database
validating email id
validating email id  how to validate the email id ?   <html> <script> function validate(){ var e=document.getElementById('email').value; var regExpObj = /(\d\d\d)-\d\d\d\d\d\d\d\d/; var reg
Validating the password field
Validating the password field  When the validate method returns back to the registration page the password field get cleared there by asking again one more time to enter the password field at the time of re-submitting the form
validating username and password from database
validating username and password from database  Hello sir, i am developing a login page. i want that when i fill data in text fields. it validate data from database. if enter data is match from database. page goes to next page
validating credentials and displaying error message in login .jsp if not valid
validating credentials and displaying error message in login .jsp if not valid  hi, i want to validate user name and password against my database table if not valid i have to display error message in my login page.how to do
validating username and password in servlet and redirect to login page with error message if not valid
validating username and password in servlet and redirect to login page with error message if not valid  hi i want to validate my login page username and password in my servlet against database and if not valid want to display
Excel Validating Value in Range
Excel Validating Value in Range In this section, you will learn how to validate a cell's value within a defined range using Apache POI. EXAMPLE In this below example, you will learn how to validate a cell's value within
Validating XML document with a DTD
Validating XML document with a DTD If an xml document is well formed i.e. syntactically correct, then it doesn't mean it is valid also. To consider...;/article> </articles> Validating With the XML Parser With Internet Explorer
Developing Login Action Class
Developing Login Action Class       In this section we will explain how to write code for login action class and database code for validating the user against database
jQuery to validate Email Address Validation
HTML form validation using jquery
HTML form validation using jquery  Is there any way for validating html elements common under a class by giving its class name in jquery validation code..that means validating all elements by using its class name if those
Login Page
Login Page  Can anyone tell me the steps to create a login page in myeclipse 7.0 and validating it with login database in db2 9.7 ??? Please tell me
RegEx
RegEx  I want to know the javascript RegEx code for validation of ( ) parenthesis.. The code is validating the parenthesis but after submit the parenthesis is disappear. what should i do
JQuery as validation controller
JQuery as validation controller  I would love to use JQuery as validation controller but i don't know how i use.Could u help me?   Here is a link that will provide you an example of validating email using jquery
servletss
such as name and password from a user and validating those credentials against some
PHP and want to use JQuery as validator
that will provide you an example of validating email using jquery. http://www.roseindia.net
Jquery form validation does not work
you a good example of validating a form using jquery with illustration
Jquery form validation does not work
you a good example of validating a form using jquery with illustration
javascript date validation using regex
;title>Validating Date format</title> <script type="text/javascript">...;/script> </head> <body> <h2>Validating Alphanumeric value...;Validating Date format</title> <script type="text/javascript">
Web Services
that represents data and the sets of validating rules.     For more
struts
to validate like email, date, double after validating it has to insert those details
Issue in JSF and Richfaces.
" and when it comes to Secretid field it will be validating tat field and rest
XML validation against a dtd -refering http://www.w3.org/1999/xmlschema
XML validation against a dtd -refering  hi i have an issue in validating an xml against dtd .As the currently used schema is http://www.w3.org/2001/xmlschema and my dtd is refering to the "http://www.w3.org/1999/xmlschema
javascript regex validation alphanumeric
; </head> <body> <h2>Validating Alphanumeric value of textBox
javascript regex validation email
;body> <h2>Validating Email Id..</h2> Email Id : <input type
javascript regex validate url
;Validating Url..</h2> Url : <input type="text" name="url" id="url" />
JavaScript regex validate validate Zip.
;/script> </head> <body> <h2>Validating Zip Code..</h2
JavaScript regex validate Telephone no.
false; } </script> </head> <body> <h2>Validating
simple javascript validation for numbers
;/head> <body> <h2>Validating mobile number..</h2> Enter

Ads