skip to main | skip to sidebar

Java Programs and Examples with Output

Pages

▼
 
  • RSS
  • Twitter
Saturday, October 6, 2012

Validating the Person Name using java

Posted by Raju Gupta at 12:45 AM – 0 comments
 
Validating user input is the bane of every software developer's existence.Regular expression can be used effectively for doing form validation.

public static boolean validatePersonName(String objText) {
        // 1) must more than 2 char
  // 2) can not be the following char
    
  String strInValidate = "`~!@#$%^&*()_+=[]{}\\|;:\",/<>?0123456789";
  try {

   
   for (int i = 0; i < objText.length(); i++) {
    if (strInValidate.indexOf(objText.substring(i, i + 1)) !=-1) {
     return false;
    }     
   }
   return true;
  } catch (Exception e) {
   return false;
  }

 }

Leave a Reply

Newer Post Older Post
Subscribe to: Post Comments ( Atom )
  • Popular
  • Recent
  • Archives
Powered by Blogger.
 
 
 
© 2011 Java Programs and Examples with Output | Designs by Web2feel & Fab Themes

Bloggerized by DheTemplate.com - Main Blogger