Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Validation for SpecialCharacter

  1. #1
    Junior Member
    Join Date
    Aug 2011
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Validation for SpecialCharacter

    if (firstName.equals("")) {
    errors.put("firstName", "Please enter your first name");
    firstName = "";
    allOk = false;
    } else {
    String expression1 = "^[!,@,#,$,%,^,&,*,(,)]+$";
    CharSequence inputStr1 = firstName;
    Pattern pattern1 = Pattern.compile(expression1);
    Matcher matcher1 = pattern1.matcher(inputStr1);

    if (matcher1.matches()) {
    allOk = true;
    } else {

    errors
    .put("firstName",
    "FirstName Should be Special Character");
    firstName = "";
    allOk = false;
    }
    }


    How To Validate the Special Character?


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Validation for SpecialCharacter

    Perhaps elaborate more on your requirements...maybe taking the following suggestions in mind:
    How To Ask Questions The Smart Way
    I don't know what you want to 'validate'...what special characters? Do you want - or not want them?

Similar Threads

  1. Help With Validation
    By bengregg in forum Loops & Control Statements
    Replies: 4
    Last Post: February 1st, 2011, 04:24 AM
  2. int / double validation
    By exnuke1972 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: January 20th, 2011, 05:08 PM
  3. Jtextfield Validation
    By nimishalex in forum AWT / Java Swing
    Replies: 8
    Last Post: December 11th, 2010, 02:42 AM
  4. Code Validation help??
    By kmh90210 in forum What's Wrong With My Code?
    Replies: 7
    Last Post: September 30th, 2010, 11:25 AM
  5. Problems with If validation
    By websey in forum Loops & Control Statements
    Replies: 1
    Last Post: November 18th, 2009, 09:43 AM