Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Validations for name in text only

 
Sonali Sharma
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Debajyoti Kundu
Ranch Hand
Posts: 30
1
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64843
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A regular expression would be a quicker and easier way to check for a pattern match.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic