[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.javascript

Regular expression for email or mobile number in one field like facebook email/mobile field in registration

ashokacharya1988

7/12/2015 3:56:00 AM


Regular expression for email or mobile number in one field like facebook email/mobile field in registration I am building a registration form in in which i am trying a make a field say email/mobile where user can either put email address or mobile number with country code.similiar approach is used in facebook registration.can anyone have solution for such regular expression. i am building the form using angularjs with its default validator.
6 Answers

Evertjan.

7/12/2015 9:07:00 AM

0

ashokacharya1988@gmail.com wrote on 12 Jul 2015 in comp.lang.javascript:

>
> Regular expression for email or mobile number in one field like facebook
> email/mobile field in registration I am building a registration form in
> in which i am trying a make a field say email/mobile where user can
> either put email address or mobile number with country code.similiar
> approach is used in facebook registration.can anyone have solution for
> such regular expression. i am building the form using angularjs with its
> default validator.
>

Show us what you have done so far.

This is not a helpdesk you order your free programming,
nor are we in general interested in the internals of Facebook.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

Steven D'Aprano

7/12/2015 12:06:00 PM

0

On Sun, 12 Jul 2015 01:55 pm, ashokacharya1988@gmail.com wrote:

>
> Regular expression for email or mobile number in one field

You *cannot* validate email addresses with a regular expression. If you try,
you will just reject valid email addresses and accept invalid ones.

The spec for valid email addresses is FORTY SEVEN pages long. And, even if
you validate that the address is *syntactically* valid, you still have no
idea whether it actually accepts mail or not. The only way to tell if an
address is valid is to send email to it.

I am sick and tired of websites that "helpfully" tell me that my email
address, which I use to send and receive hundreds of emails every day, is
not valid. If you try to validate an email address, STOP, you're doing it
wrong.

http://davidcel.is/posts/stop-validating-email-addresses-w...

http://www.mdswanson.com/blog/2013/10/14/how-not-to-validate-email-addr...



--
Steven

JR

7/13/2015 7:51:00 PM

0

On 12-07-2015 00:55, ashokacharya1988@gmail.com wrote:
>
> Regular expression for email or mobile number in one field like
> facebook email/mobile field in registration I am building a
> registration form in in which i am trying a make a field say
> email/mobile where user can either put email address or mobile
> number with country code.similiar approach is used in facebook
> registration.can anyone have solution for such regular expression. i
> am building the form using angularjs with its default validator.
>

You may try the HTML5 input type=email [1] which has good support by
modern browsers [2].

Also, check out an example Regex by Cody Lindley at debuggex [3].

[1]
<http://www.w3.org/TR/2014/CR-html5-20140204/forms.html#e-m...(type=email)>

[2] <http://caniuse.com/#feat...

[3] <https://www.debuggex.com/r/kk8zYcDftY...

--
Joao Rodrigues

Dr J R Stockton

7/13/2015 10:14:00 PM

0

In comp.lang.javascript message <55a2580f$0$1638$c3e8da3$5496439d@news.a
straweb.com>, Sun, 12 Jul 2015 22:05:36, Steven D'Aprano
<steve@pearwood.info> posted:

>On Sun, 12 Jul 2015 01:55 pm, ashokacharya1988@gmail.com wrote:
>
>>
>> Regular expression for email or mobile number in one field
>
>You *cannot* validate email addresses with a regular expression. If you try,
>you will just reject valid email addresses and accept invalid ones.
>
>The spec for valid email addresses is FORTY SEVEN pages long. And, even if
>you validate that the address is *syntactically* valid, you still have no
>idea whether it actually accepts mail or not. The only way to tell if an
>address is valid is to send email to it.
>
>I am sick and tired of websites that "helpfully" tell me that my email
>address, which I use to send and receive hundreds of emails every day, is
>not valid. If you try to validate an email address, STOP, you're doing it
>wrong.
>
>http://davidcel.is/posts/stop-validating-email-addresses-w...
>
>http://www.mdswanson.com/blog/2013/10/14/how-not-to-valid...
>addresses.html


One cannot validate a mobile number fully with a RegExp either.

One can check for an attempted E-mail address. From memory, check for
yourself, all are of the form
something only-@ something dot something
and anything else _must_ be wrong.

--
(c) John Stockton, Surrey, UK. ¬@merlyn.demon.co.uk Turnpike v6.05 MIME.
Web <http://www.merlyn.demon.... - FAQish topics, acronyms, & links.

Steven D'Aprano

7/14/2015 2:48:00 AM

0

On Tue, 14 Jul 2015 08:13 am, Dr J R Stockton wrote:

> One can check for an attempted E-mail address. From memory, check for
> yourself, all are of the form
> something only-@ something dot something
> and anything else _must_ be wrong.


Local email addresses don't even require a @ sign, so if your app is on an
intranet you might have valid addresses like

support
helpdesk

but let's assume you're on the internet so there must be at least one @.

Yes, I said *at least one*, not exactly one.

Does there need to be a dot after the @ sign? NO no no no.

user@com
user@localserver
user@[IPv6:2001:db8::1]

are all syntactically valid email addresses. Now that there are a whole lot
more top level domains possible than just .com and .org, you could have:

fred@accountants
1234567@international




--
Steven

Thomas 'PointedEars' Lahn

7/14/2015 2:38:00 PM

0

Joao Rodrigues wrote:

> On 12-07-2015 00:55, ashokacharya1988@gmail.com wrote:
>> Regular expression for email or mobile number in one field like
>> facebook email/mobile field in registration

It does not make sense to repeat the subject line verbatim in the message
body.

>> I am building a registration form in in which i am trying a make a field
>> say email/mobile where user can either put email address or mobile
>> number with country code.similiar approach is used in facebook
>> registration.can anyone have solution for such regular expression. i
>> am building the form using angularjs with its default validator.
>
> You may try the HTML5 input type=email [1] which has good support by
> modern browsers [2].
>
> Also, check out an example Regex by Cody Lindley at debuggex [3].

Lindleyâ??s expression is insufficient, not least because of new TLDs [1].
The HTML5 Specification has a better expression in the referred section
insofar that it supports those; however, it does not support IDNs which
should be encoded with Punycode by the HTTP client, not the user [2].

However, you have overlooked that the OP is using AngularJS, and had they
googled for â??angular e-mailâ? they would have found the proper solution for
them already.

Of course, it will be difficult to have the *same* input field for an e-mail
address *or* a mobile phone number *and* properly validate either. An e-
mail address is not a valid phone number and vice-versa; and phone numbers
cannot be properly validated in an international context, which means they
cannot be properly recognized, which means that they cannot be told from an
invalid e-mail address.

[1] <http://newgtlds.icann.org/en/program-status/delegated-s...
[2] <https://en.wikipedia.org/wiki/Internationalized_domai...

--
PointedEars
FAQ: <http://PointedEars.... | SVN: <http://PointedEars.de...
Twitter: @PointedEars2 | ES Matrix: <http://PointedEars.de/es-...
Please do not cc me. / Bitte keine Kopien per E-Mail.