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

View Entire Topic
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