cancel
Showing results for 
Search instead for 
Did you mean: 

Validation of a Address String in webdynpro

venkatakalyan_karanam
Active Contributor
0 Kudos

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

Accepted Solutions (1)

Accepted Solutions (1)

venkatakalyan_karanam
Active Contributor
0 Kudos

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

Former Member
0 Kudos

Hi,

Use following code

Pattern p=null;

p=Pattern.compile("[a-zA-Z][
w
s]*");

Matcher m=p.matcher(name);

if(m.matches())

return true;

else

return false;

Ragarda

LakshmiNarayana

Former Member
0 Kudos

Hi,

Try this:

[code]String pattern = "[
W&&[^/-]]+$";

Pattern validator = Pattern.compile(pattern) ;

Matcher matcher = validator.matcher("<input string from user>");

if(matcher.matches()){

//error...throw message

}

else {

//ok

}[/code]

Regards,

Satyajit.

Message was edited by:

Satyajit Chakraborty

Former Member
0 Kudos

Hi chakri

i used ur code.But this is failed some of the cases.

If i enter any of wordcharacter +non word char

it will not give error.

Plz provide solution

Thanks & Regards

Hazrath.G

Former Member
0 Kudos

Hi,

Trying again

String pattern 	= "[\W&&[^/-]]";
String input	= "<input from user>";
String first	= input.replaceAll(pattern, "");
		
if(input.compareTo(first) != 0){
    //error...throw error message
}
else
   //ok
}

Regards,

Satyajit.

Former Member
0 Kudos

Thanks chakri

It is working fine.

Thanks & Regards

Hazrath.G

Former Member
0 Kudos

Chakri

Once again thanks for ur reply.

But i have no chance to give the points to u.Why Bcz this question is actualy posted by Kalyan

Thanks & Regards

Hazrath.G

Answers (4)

Answers (4)

Former Member
0 Kudos

kalyan

Did u get answer for that?

If u got the answer plz forward to mail id:

Hazrath04@gmail.com

Thanks & Regards

GH.Guptha

Former Member
0 Kudos

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

Former Member
0 Kudos

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

Former Member
0 Kudos

Hi,

Use patterns to check the criteria

Refer this for the hints

/people/valery.silaev/blog/2005/11/29/800format-your-way

Regards

Ayyapparaj