Fast way for email, phone input validation

272 views
Skip to first unread message

mma

unread,
Jun 27, 2011, 7:25:35 AM6/27/11
to google-we...@googlegroups.com
Hi there!

I'm trying to implement input validation for email and phone fields.

I'm struggling with gwt-validation framework.

Is there any fast, simple way to do it?

Thanks,
Best regards

mohamed salah

unread,
Jun 27, 2011, 7:42:39 AM6/27/11
to google-we...@googlegroups.com

salam
there mohammad salah
validate your phone create method validate your email
 
---------------------------------------------------------------
  // this method is email for example    M...@mm.com

public static boolean isEmail(final String value) {
        boolean valid = true;
        if (value != null) {
            valid = value.matches(".+@.+\\.[a-z]+");

            if (value.contains(" ")) {
                valid = false;
            }
        }

        return valid;

    }
---------------------------------------------------------------

// this method is email is not empty
public static boolean isEmptyValue(final String value) {
        boolean valid = true;
        if (value == null) {
            return valid = false;
        }
        if (value.trim().equals("")) {
            return valid = false;
        }

        return valid;
    }
---------------------------------------------------------------
// this method is email min lenght
public static boolean checkMinlength(final String value, final int minLength) {
        boolean valid = true;
        if (value != null) {
            if (value.length() < minLength) {
                valid = false;
            }

        }

        return valid;

    }

---------------------------------------------------------------
// this method is MaX length

public static boolean checkMaXlength(final String value, final int maxLength) {
        boolean valid = true;
        if (value != null) {
            if (value.length() > maxLength) {
                valid = false;
            }

        }

        return valid;

    }
---------------------------------------------------------------

validate is Fone
---------------------------------------------------------------
create varible
public static final String RGEX_PHONE_ONLY = "^\\(?(\\d{3}-)\\)?(\\d{3}-)?(\\d{4})$";
this varible validate to phone for example method

---------------------------------------------------------------
//this method is Phone for example 111-111-1111 is true.
1111-111-1111 is not true
1111-1111-1111 is not true
111-111-111 is not true
and contune.
this method .
---------------------------------------------------------------
public static boolean isPhone(String value) {
        boolean valid = false;
        valid = value.matches(RGEX_PHONE_ONLY);
        if (valid) {
            valid = true;
        }
        return valid;
    }
---------------------------------------------------------------
Regard: Senior : Mohamed salah hasan
Mobile :+20106594094
tel     :+2024460320
Mail:mohamedhas...@gmail.com

marco....@gmail.com

unread,
Jun 27, 2011, 7:53:12 AM6/27/11
to google-we...@googlegroups.com
Thanks!

Sent from my BlackBerry® wireless device


From: mohamed salah <mohamedhas...@gmail.com>
Date: Mon, 27 Jun 2011 13:42:39 +0200
Subject: Re: Fast way for email, phone input validation
--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To post to this group, send email to google-we...@googlegroups.com.
To unsubscribe from this group, send email to google-web-tool...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.

mohamed salah

unread,
Jun 27, 2011, 7:57:31 AM6/27/11
to google-we...@googlegroups.com
--

-----------------------------------------
not at all

Regard: Mohamed salah hasan
Mobile :+20106594094
tel     :+2024460320


David Goodenough

unread,
Jun 27, 2011, 8:31:31 AM6/27/11
to Google-We...@googlegroups.com
Note this is only valid for US phone numbers. It takes no account
of country codes or other international phone formats.

David


> and contune.
> this method .
> ---------------------------------------------------------------
> public static boolean isPhone(String value) {
> boolean valid = false;
> valid = value.matches(RGEX_PHONE_ONLY);
> if (valid) {
> valid = true;
> }
> return valid;
> }
> ---------------------------------------------------------------

> *Regard: Senior : Mohamed salah hasan
> Mobile :+20106594094
> tel :+2024460320
> Mail:mohamedhas...@gmail.com*

mohamed salah

unread,
Jun 27, 2011, 8:55:59 AM6/27/11
to google-we...@googlegroups.com

--
salaam
it ok this method 
is only valid for US phone numbers.  It takes no account
of country codes or other international phone formats.

but this format is US phone format
ok
Possible change your format Depending on the phone number isA

for example (1)
    public static final String RGEX_PHONE_ONLY = "^\\(?(\\d{3}-)\\)?(\\d{3}-)?(\\d{4})$";

is true 111-111-1111

for example (2)

public static final String RGEX_PHONE_ONLY = "^\\(?(\\d{4}-)\\)?(\\d{4}-)?(\\d{3})$";

is true 1111-1111-111

for example (3)

public static final String RGEX_PHONE_ONLY = "^\\(?(\\d{2}-)\\)?(\\d{3}-)?(\\d{4})$";

is true 11-111-1111

thanks
mohammad salah
Take Your Time Man


------------------------------------------

Regard: Mohamed salah hasan
Mobile :+20106594094
tel     :+2024460320


Marco Alves

unread,
Jun 27, 2011, 4:01:03 PM6/27/11
to google-we...@googlegroups.com
Thanks for the note.

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To post to this group, send email to google-we...@googlegroups.com.
To unsubscribe from this group, send email to google-web-tool...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.




--
Marco Manteigas Alves
tlm: 96 983 46 23
skype: marco.m.alves
Reply all
Reply to author
Forward
0 new messages