Limiting Punctuation Characters In Code
Limiting Punctuation Characters In Code
- Subject: Limiting Punctuation Characters In Code
- From: "Jonathan Fleming" <email@hidden>
- Date: Wed, 05 Feb 2003 12:44:18 +0000
You'll all probably think I'm dippy, and I would be if I didn't ask.
The bit of code below tests if a name is not null and valid and doesn't
allow any puctuation in it, however, i would like the user to be able to use
a hypen (dash -) in their name if they have a double fist name like
"Lesley-Ann" or "Mary-Lee"... This would be the only puctuation mark they
can use in a name but I am having trouble writing this into the code
basically because I don't know how and I'm wasting time muddling about with
it. Can anyone help please.
Many thanks
Jonathan
Here's the code:
/**
* Test if name is valid
**/
public String isValidName(String value)
{
String msg = null;
if (value!=null)
{
for (int index=0; index<value.length(); index++)
{
char c = value.charAt(index);
if (!Character.isLetter(c))
{
msg = "The value \"" + value + "\" is not a valid name.
Avoid numbers and punctuation. Try something like \"Mary\"";
break;
}
}
}
else
{
msg = "A valid name is required. Avoid numbers and punctuation.
Try something like \"Mary\"";
}
return (msg);
}
_________________________________________________________________
It's fast, it's easy and it's free. Get MSN Messenger today!
http://messenger.msn.co.uk
_______________________________________________
webobjects-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/webobjects-dev
Do not post admin requests to the list. They will be ignored.