zoukankan      html  css  js  c++  java
  • ValidationUtils 验证工具

    package com.appnirman.vaidationutils;

    import android.content.Context;

    import java.util.regex.Matcher;
    import java.util.regex.Pattern;

    public class ValidationUtils {
    private final Context mContext;



    public ValidationUtils(Context mContext) {
    this.mContext = mContext;
    }

    public boolean isValidConfirmPasswrod(String confirmPassword, String password) {
    if (!confirmPassword.equals(password)) {
    return false;
    } else {
    return true;
    }
    }

    public boolean isValidAddress(String address) {
    if (address == null || address.equals("")) {
    return false;
    } else {
    return true;
    }
    }

    public boolean isValidPincode(String pincode) {
    if (pincode == null) {
    return false;
    } else {
    String PINCODE_PATTERN = "^[0-9]{6}$";

    Pattern pattern = Pattern.compile(PINCODE_PATTERN);
    Matcher matcher = pattern.matcher(pincode);
    return matcher.matches();
    }
    }


    public boolean isValidMobile(String mobile) {
    Pattern p = Pattern.compile("^[789]\d{9,9}$");
    if (mobile == null) {
    return false;
    } else {
    Matcher m = p.matcher(mobile);
    return m.matches();
    }
    }

    public boolean isValidPassword(String password) {
    Pattern p = Pattern.compile("((?!\s)\A)(\s|(?<!\s)\S){8,20}\Z");
    if (password == null) {
    return false;
    } else {
    Matcher m = p.matcher(password);
    return m.matches();
    }
    }

    public boolean isValidEmail(String email) {
    if (email == null) {
    return false;
    } else {
    return android.util.Patterns.EMAIL_ADDRESS.matcher(email).matches();
    }
    }

    public boolean isValidLastName(String lastName) {
    Pattern p = Pattern.compile("^[a-zA-Z]{3,20}$");
    if (lastName == null) {
    return false;
    } else {
    Matcher m = p.matcher(lastName);
    return m.matches();
    }
    }

    public boolean isValidFirstName(String firstname) {
    Pattern p = Pattern.compile("^[a-zA-Z]{3,20}$");
    if (firstname == null) {
    return false;
    } else {
    Matcher m = p.matcher(firstname);
    return m.matches();
    }
    }

    public boolean isValidAge(String age) {
    Pattern p = Pattern.compile("^[1-9]{1,3}$");
    if (age == null||age.equals("")) {
    return false;
    }else {
    Matcher m = p.matcher(age);
    return m.matches();
    }
    }

    public boolean isEmptyEditText(String s) {
    if(s == null|| s.equals("")){
    return false;
    }else {
    return true;
    }
    }
    }
  • 相关阅读:
    9-python 的ProxyHandler处理器(代理设置)
    2018.2.7 css 的一些方法盒子模型
    2018.2.6 JS-判断用户浏览器
    2018.2.5 PHP如何写好一个程序用框架
    2018. 2.4 Java中集合嵌套集合的练习
    2018.2.3 Centos 的vim好看的主题配置及JDK的安装配置
    2018.2.2 java中的Date如何获取 年月日时分秒
    2018.2.2 JavaScript中的封装
    2018.1.30 PHP编程之验证码
    2018.1.29 计算机二级错题汇总(二)
  • 原文地址:https://www.cnblogs.com/wutianlong/p/6265750.html
Copyright © 2011-2022 走看看