Skip to Content

Validation of a Address String in webdynpro

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

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

5 Answers

  • Best Answer
    Posted on Dec 03, 2007 at 01:37 PM

    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

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Dec 03, 2007 at 01:30 PM

    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

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Dec 03, 2007 at 01:23 PM

    Hi,

    Use patterns to check the criteria

    Refer this for the hints

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

    Regards

    Ayyapparaj

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Dec 03, 2007 at 01:27 PM

    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

    http://java.sun.com/j2se/1.4.2/docs/api/java/util/regex/Pattern.htmlhttp://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>

    regards

    Sumit

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Dec 04, 2007 at 06:55 AM

    kalyan

    Did u get answer for that?

    If u got the answer plz forward to mail id:

    Hazrath04@gmail.com

    Thanks & Regards

    GH.Guptha

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.