Showing posts with label validation. Show all posts
Showing posts with label validation. Show all posts

June 07, 2013

Validating 2 digit number in java Swing using Regular expression

How to check whether a number is two digit number in java swing using regular expression validator

Here you can see how rollnumber is verified

package swing;
public class RollNumberValidatorImpl  extends InputVerifier{
public boolean verify(String input) {
         boolean isRollNumber = false;
         String rollNumber = input;
         if(rollNumber!=null && rollNumber.length()>0){
             isRollNumber = rollNumber.matches("\\d{1,2}")? true: false;
         }
         return isRollNumber;
    }
    public static void main(String[] args) {
        RollNumberValidatorImpl r = new RollNumberValidatorImpl();
        System.out.println(r.verify("01"));
    }
}


+Java

How to create a JTextfield in java that accepts only digits

The code verify for four digit number in java textfield First of all you need to create a class that extends inputverifier, then you have to register this class with your text field

class test{ public static void main(string arg){
JTextField motorolaText = new JTextField();
motorolaText.setInputVerifier(new FirmCodeValidatorImpl()); } }


The above code will shows you how to call the validation class, and the below one is validation class, i used regular expression here to validate the input

import javax.swing.InputVerifier;
import javax.swing.JComponent;
import javax.swing.JTextField;

public class FirmCodeValidatorImpl  extends InputVerifier{
   
    @Override
    public boolean verify(JComponent input) {
        boolean isFirmCode = false;
        String firmCode = null;
        JTextField textField = (JTextField) input;
        if(textField!=null){
            firmCode = textField.getText();
            isFirmCode = firmCode.matches("\\d{4}")? true: false;
        }
        return isFirmCode;
    }
   }

How to check whether a number is two digit in java



if you are satisfied with the code please provide your comments


http://belazy.blog.in/

October 14, 2012

Phone Number validation in java

Regular expression phone number validation in java

This example code is for phone number validation in java using regular expression and for internet protocol address validation in java


/**
 *
 * @author belazy
 * @version validates1.0
 */
public class Validator implements ValidaterInterface {


/**
 *
 * @see deeps
 * @param
 * @return boolean
 * Description : phone number validator
 * Date : Sep 19, 2007
 * Coded by : belazy
 */
public boolean phoneNumberValidator(String phoneNumber) {
        boolean isValid = false;
        String expression = "^\\(?(\\d{3})\\)?[- ]?(\\d{3})[- ]?(\\d{4})$";
        CharSequence inputStr = phoneNumber;
        Pattern pattern = Pattern.compile(expression);
        Matcher matcher = pattern.matcher(inputStr);
        if (matcher.matches()) {
            isValid = true;
        }
        return isValid;
    }

/**
 *
 * @see deeps
 * @param
 * @return boolean
 * Description : ip v4 validator
 * Date : Sep 19, 2007
 * Coded by : belazy
 */
public boolean ipaddressV4Validator(String ip) {
        String[] parts = ip.split("\\.");
        if (parts.length < 5) {
            for (String s : parts) {
                int i = Integer.parseInt(s);
                if (i < 0 || i > 255) {
                    return false;
                }
            }
        } else {
            return false;
        }
        return true;
    }


}



To trace the caller details in your java apps you can use true caller api

True caller API Documentation 


http://belazy.blog.com/

January 07, 2012

Email validation in java

Email validator in java

How to validate an email address in using java regular expression. complete source code is available here. If you need to validate an email address through mail then we need to create a java web application.

  Here i created a function emailValidator with a parameter type string. the function will return true or false. call the function where ever you need it

/**
*
* @see
* @param
* @return boolean
* Description : email validator
* Date : Dec 4, 2009
* Coded by : belazy
*/
public boolean emailValidator(String email) {
boolean isValid = false;
String expression = “^[\\w\\.-]+@([\\w\\-]+\\.)+[A-Z]{2,4}$”;
CharSequence inputStr = email;
Pattern pattern = Pattern.compile(expression, Pattern.CASE_INSENSITIVE);
Matcher matcher = pattern.matcher(inputStr);
if (matcher.matches()) {
isValid = true;
}
return isValid;
}


Please try the code and provide us a feedback  

Facebook comments