package com.ramos.munoz.tesis;

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

import android.text.InputFilter;
import android.text.Spanned;
import android.widget.EditText;

public class Validacion {

    public static boolean isVacio(EditText campo) {

	if (campo.getText().toString() == null) return true;
	if (campo.getText().toString().equals("")) return true;
	if (campo.getText().toString().matches("")) return true;
	if (campo.getText().toString().matches(" ")) return true;

	return false;
    }

    public static boolean isCorreo(String correo) {
	Pattern pat = null;
	Matcher mat = null;
	pat = Pattern.compile("^([0-9a-zA-Z]([_.w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-w]*[0-9a-zA-Z].)+([a-zA-Z]{2,9}.)+[a-zA-Z]{2,3})$");
	mat = pat.matcher(correo);
	if (mat.find()) {
	    System.out.println("[" + mat.group() + "]");
	    return true;
	} else {
	    return false;
	}
    }

    public static boolean isPatente(String patente) {

	String[] series = patente.split("-");
	if (series.length != 3) return false;

	return false;
    }

    public static boolean isCampoConCeros(Integer campo) {
	if (campo == 0) return true;
	return false;
    }

    public static InputFilter filtroPatente = new InputFilter() {
	@Override
	public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) {
	    for (int i = start; i < end; i++) {

		if (i < source.length()) {
		    if (source.charAt(i) == " ".toCharArray()[0]) {
			return "";
		    }
		}

	    }

	    return null;
	}
    };

}
