|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Field Validation
Hi there,
I want to make some validation for the email field in my form, I want to make sure that the "@" character is exists and the "." is exists also and the email shouldn't start with a space, name@domain.com // start with a space namedomain.com // doesn't have a "@" name@domaincom // doesn't have a "." So, I want to avoid people keep on submitting invalid addresses. How can I achieve this? |
|
#2
|
|||
|
|||
|
RE: Field Validation
|
|
#3
|
|||
|
|||
|
RE: Field Validation
Here's a client-side version:
Code:
<script>
function checkemail(e){
var email=String(e.value);
if (email){
var reg=/^[w-]+(.[w-]+)*@[a-z0-9-]+(.a-z0-9-]+)*$/i
if (!reg.test(email)){
alert("The email address you have entered is invalid.");
if (String(navigator.appName)!='Netscape'){
e.focus();
}
} else {
alert("EMAIL OK");
}
}
}
</script>
|
|
#4
|
|||
|
|||
|
RE: Field Validation
The problem with client side scripting is that the client can choose to ignore it...
|
|
#5
|
|||
|
|||
|
RE: Field Validation
That's why I do it on both ends...
|
|
#6
|
|||
|
|||
|
RE: RE: Field Validation
Quote:
Why bother doing it client side if you do it server side? Surely that just increases filesize? Unless you use it for a JS alert() ??? |
|
#7
|
|||
|
|||
|
RE: Field Validation
Yeah, it's just for the user's benefit...
|
|
#8
|
|||
|
|||
|
RE: Field Validation
it is always A Good Thing [tm] to check user input on both client and server side.
let me explain: when u write some js code to check 10-15 input fields, it can add only about 1-2k on the html page, but when a user submits a page with error fields, u have to send him a hole page back, which is usualy over 50k of html (with adds and stuff) so, it is both for user's benefith, and for less traffic on your site... |
|
#9
|
|||
|
|||
|
RE: Field Validation
Good point. I hadn't thought of that.... d'oh!
|
|
#10
|
|||
|
|||
|
RE: Field Validation
don't worry. it will all come with time and expiriense.
also, wondering on this kind of forums helps. well, just a year or two ago, i didn't know smth like this, and now i do. and if i can learn, i think everybody can ;))) |
|
#11
|
|||
|
|||
|
RE: Field Validation
That's the good thing - I would class myself as a good coder (advanced knowledge of PHP, HTML, CSS; resonable knowledge of Perl, JavaScript, MySQL) yet I come to these forums not only to help others but to learn. Since I have taught myself and not used a book, I have a particular style meaning that when I come across a problem, I would use a set method to solve it.
For example, up until about 3 weeks ago, I was trying to use functions to add data to the end of an array, not knowing that you could just use: $array[] = $data; It's the simple things that are so beneficial to your coding. |
|
#12
|
|||
|
|||
|
RE: Field Validation
to make it a "super" check, how about adding the ability to open a temporary connection to the hostname provided to see if it actually exists.
|
|
#13
|
|||
|
|||
|
RE: Field Validation
oh. well that makes sense
|
|
#14
|
|||
|
|||
|
RE: Field Validation
how can ivalidate email using array.
|
|
#15
|
|||
|
|||
|
RE: Field Validation
I have a FORM built and I want to add a simple validation code for the email address. So far nothing works with my current FORM. Any ideas ??? (current FORM located here: http://www.partsadventure.com/request2.htm )
|
![]() |
| Viewing: Codewalkers Forums > PHP Related > PHP Coding > Field Validation |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|