on 11-17-2007 4:48 AM
Hi experts
I have created form in Webdynpro ,which will accept input values from the user .There is one input field which takes the email address of the user .How do i validate this input field as it should only take in the input of the pattern someone@domain.com,if anyother format is entered it should give an error saying it invalid format.
Thanks and Regards
Hazrath
Hi,
1) Create a validating action or else make the attibute bound to the text box a calculated one.
2) Inside the action or inside the setter if the attribute is calculated write the follwowing code.
String input = // your attribute
//Checks for email addresses starting with
//inappropriate symbols like dots or @ signs.
Pattern p = Pattern.compile("^
.|^
@");
Matcher m = p.matcher(input);
if (m.find())
System.err.println("Email addresses don't start" +
" with dots or @ signs.");
//Checks for email addresses that start with
//www. and prints a message if it does.
p = Pattern.compile("^www
.");
m = p.matcher(input);
if (m.find()) {
System.out.println("Email addresses don't start" +
" with \"www.\", only web pages do.");
}
p = Pattern.compile("[^A-Za-z0-9
.
@_
-~#]+");
m = p.matcher(input);
StringBuffer sb = new StringBuffer();
boolean result = m.find();
boolean deletedIllegalChars = false;
while(result) {
deletedIllegalChars = true;
m.appendReplacement(sb, "");
result = m.find();
}
// Add the last segment of input to the new String
m.appendTail(sb);
input = sb.toString();
if (deletedIllegalChars) {
System.out.println("It contained incorrect characters" +
" , such as spaces or commas.");
}
http://java.sun.com/developer/technicalArticles/releases/1.4regex/
Regards
Ayyapparaj
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi
try the following for validation
try {
Pattern p=null;
p=Pattern.compile(".@.
.[a-z]+");
Matcher m=p.matcher(name);
if(m.matches())
return true;
else
return false;
} catch (Exception e) {
return false;
}
Regards
Roop
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
You can check the email address being entered by the user using.
if(wdContext.currentContextElement().get<attribute>().matches(<regular expression>)
{
//perform your logic for correct email address.
}
else
{
wdComponentAPI.getMessageManager().reportException("Invalid Email address",true);
}
Regards,
Murtuza
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.