aspose file tools*
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
JavaRanch » Java Forums » Java » JSP
Bookmark "Validations for name in text only" Watch "Validations for name in text only" New topic
Author

Validations for name in text only

Sonali Sharma
Greenhorn

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
Greenhorn

Joined: Sep 14, 2011
Posts: 23
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.

eg:
String s="Hello";
if(s.length()>=23){
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
Marshal

Joined: Jan 10, 2002
Posts: 61654
    
  67

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


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Validations for name in text only