/    Sign up×
Community /Pin to ProfileBookmark

Validation.

Hi there.

We are using the following code to check whether submitted e-mail addresses are properly formed, not blank etc…
Can you advise whether this is quite accurate and decent as there seems to be many around!

[code=php]
if (!preg_match(‘/[^x00-x20()<>@,;:\”.[]x7f-xff]+(?:.[^x00-x20()<>@,;:\”.[]x7f-xff]+)*@[^x00-x20()<>@,;:\”.[]x7f-xff]+(?:.[^x00-x20()<>@,;:\”.[]x7f-xff]+)+/’, $_POST[‘EMAIL’])) {
$msg .= “<li>Your e-mail address is invalid.</li>n”;
}
[/code]

Also, how can you check that a submitted field begins with ‘#’, for example if something was submitted without it beginning with # an error is shown, if JUST # was submitted (so it’s theoretically blank) another error is shown?

Many thanks!

Regards,

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@96turnerriJan 23.2005 — well i use this which works fine
!eregi("^[_a-z0-9-]+(.[_a-z0-9-]+)*@[a-z0-9-]+(.[a-z0-9-]+)*(.[a-z]{2,3})$", $_POST["email"])

as for the '#' deal

<i>
</i>&lt;?php
foreach($_POST as $key =&gt; $val) {
if(substr($val, 0, 1) == "#" &amp;&amp; strlen($val) &gt;= 1) {
//do nothing
} else {
echo "Error in: '$key'&lt;br /&gt;";
}
}
?&gt;
Copy linkTweet thisAlerts:
@DanUKauthorJan 25.2005 — Hi there.

Many thanks for that.

Would you say your code was more accurate for e-mail validation? If so, I'll swap out my e-mail validation code and use that.

Regards,
×

Success!

Help @DanUK spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.24,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...