on 12-03-2007 1:20 PM
Hi experts
I have some problem in the validation of the Address field of data type String
The user is permitted to enter alphabet and the numbers but not special characters except '-' and '/'. I should not allow the user to enter any special characters like @,!,#,$,%,^,&,*,square braces,paranthesis like this.I should validate when ever a user enters a special characters of that type and throw an error message.Can you please any one can give the guide lines or code snippet which gives the remedy for my problem.
Thanks and Regards
Kalyan
Hi Sumit
I didnt understand your expression how you framed that and can you please tell me how that expression can be written in my case assume that String must consists of Numeric 0 to 9 all alphabetic any case and - and / only .
It should not contain any other characters like !,@,#,$,%,^,&,*,(,),_,+,=,{,},[,],:,;,",',<,>,?,|,\ Here each character is seperated with ,.
Can you please give the expression which you framed in your code.
Kalyan
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
kalyan
Did u get answer for that?
If u got the answer plz forward to mail id:
Hazrath04@gmail.com
Thanks & Regards
GH.Guptha
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi! venkatakalyan,
1.Create an array of character to keep the all your special character.
2.create a method to check the validity of the given input string like --
boolean checkInputString(String name) { }
inside this method parse your input string and compare the individual character of string with elements of array having special character.if you are able to find any match return false.
regards,
Mithileshwar
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Kalyan,
I did this for email id validation . u can change the code for ur requirement.
static final String expression = "(
s|>|^)(?!(:|www
.|
.))[A-Za-z0-9_.-]@([A-Za-z0-9_-]
.)+[A-Za-z]{2,4}(
s|
W|_|<|$)";
public boolean validateEmailId( java.lang.String emailId )
{
//@@begin validateEmailId()
java.util.regex.Pattern pattern;
String value = null;
boolean isValid = false;
try {
value = emailId.toString();
pattern = java.util.regex.Pattern.compile(expression);
isValid = pattern.matcher(value).matches();
} catch (Exception e) {
}
return isValid;
//@@end
}
for more info u can check this link
<a href="http://java.sun.com/j2se/1.4.2/docs/api/java/util/regex/Pattern.html">http://java.sun.com/j2se/1.4.2/docs/api/java/util/regex/Pattern.html</a>
regards
Sumit
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Use patterns to check the criteria
Refer this for the hints
/people/valery.silaev/blog/2005/11/29/800format-your-way
Regards
Ayyapparaj
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
86 | |
10 | |
10 | |
9 | |
6 | |
6 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.