File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSP and the fly likes Validations for name in text only Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Validations for name in text only" Watch "Validations for name in text only" New topic

Validations for name in text only

Sonali Sharma

Joined: Nov 24, 2011
Posts: 1
Hello i want to have the validation o the name so that it must be text and less than 26 characters.What coding i have to do and where i have to put this coding?

Astrology in Delhi | Corporate Event Management | Seo Services Delhi
Debajyoti Kundu

Joined: Sep 14, 2011
Posts: 27
Hi Sonali,
Is this validation is for value of some text box of a html page or for a String variable in java?

If it's html then you need javascript.

If it's java code then use a loop and check ASCII value of each character comes under 65-90 or 97-122(for A-Z and a-z). Keep this loop inside a if block which will check it's length.

String s="Hello";
for(int i=0;i<s.length;i++)
int ch=(int)s.charAt(i);
// now check value of ch to find if the string contains any thing other that characters or not. you and add the range of numerical digits in condition checking if you want those
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63873

A regular expression would be a quicker and easier way to check for a pattern match.

[Asking smart questions] [About Bear] [Books by Bear]
I agree. Here's the link:
subject: Validations for name in text only
It's not a secret anymore!