cancel
Showing results for 
Search instead for 
Did you mean: 

Regarding Inputfield

Former Member
0 Kudos

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

Accepted Solutions (0)

Answers (4)

Answers (4)

Former Member
0 Kudos

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

Former Member
0 Kudos

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

Former Member
0 Kudos

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

Former Member
0 Kudos

chk it