Approach to form validation

User avatar
agibsonsw
SilverLounger
Posts: 2403
Joined: 05 Feb 2010, 22:21
Location: London ENGLAND

Approach to form validation

Post by agibsonsw »

Hello. JavaScript et al.

I'm interested in opinions for validating data within a form. Is the following correct:

1. An email will always include an at '@' sign. Will it also (always) include a period (.)? And no spaces.
2. It's (almost) impossible to validate an URL. It can include any characters, including spaces (%20)?

Andy.
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.

User avatar
HansV
Administrator
Posts: 78411
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Approach to form validation

Post by HansV »

Search Google for regular expressions to validate e-mail addresses and URLs. There are some very clever solutions out there.
Best wishes,
Hans

User avatar
agibsonsw
SilverLounger
Posts: 2403
Joined: 05 Feb 2010, 22:21
Location: London ENGLAND

Re: Approach to form validation

Post by agibsonsw »

I'm happy working with regular expressions, but I just want to confirm - does every e-mail address contain @, a dot and no spaces?

I've seen many examples that try to validate URLs, and a lot of advice that it is not sensible to try this. Perhaps every url contains at least one of these
characters: \ / or . (period)? Andy.
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.

User avatar
stuck
Panoramic Lounger
Posts: 8163
Joined: 25 Jan 2010, 09:09
Location: retirement

Re: Approach to form validation

Post by stuck »

If I use the 'Block sites' feature on my Netgear router and use . (period) as the keyword then it warns me that this will block all sites. That suggests to me that all URLs do contain a . (period).

Ken

User avatar
agibsonsw
SilverLounger
Posts: 2403
Joined: 05 Feb 2010, 22:21
Location: London ENGLAND

Re: Approach to form validation

Post by agibsonsw »

Thank you. I just remembered that some browsers or search engines will even accept a single word (bbc, ebey, etc.) and 'www.' seems to be assumed most often these days.

Perhaps the only way to sensibly validate is to use a server-side script and send a http (or ping - is that the term?) request.

I'm still curious as to whether every email contains a dot . Andy.
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.

User avatar
DaveA
GoldLounger
Posts: 2599
Joined: 24 Jan 2010, 15:26
Location: Olympia, WA

Re: Approach to form validation

Post by DaveA »

agibsonsw wrote:Thank you. I just remembered that some browsers or search engines will even accept a single word (bbc, ebey, etc.) and 'www.' seems to be assumed most often these days.
I'm still curious as to whether every email contains a dot . Andy.
These browser are smart enough to add the ".com" or even a FEW of the other well known sites, but not all of them

Yes, ALL domains have a "Dot" something, this includes websites and email addresses.

Have a good read at http://en.wikipedia.org/wiki/Domain_Name_System" onclick="window.open(this.href);return false;

I guess that you could use anything you wanted as long as you could convince "ICANN " that you really needed to. :laugh: :flee: :hairout:
I am so far behind, I think I am First :evilgrin:
Genealogy....confusing the dead and annoying the living

User avatar
HansV
Administrator
Posts: 78411
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Approach to form validation

Post by HansV »

As Dave mentions, every (complete) e-mail address contains at least one dot after the @. And spaces aren't allowed.
Best wishes,
Hans

User avatar
HansV
Administrator
Posts: 78411
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Approach to form validation

Post by HansV »

Best wishes,
Hans

User avatar
agibsonsw
SilverLounger
Posts: 2403
Joined: 05 Feb 2010, 22:21
Location: London ENGLAND

Re: Approach to form validation

Post by agibsonsw »

Thank you.
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.