Jump to content

Realtime form validation, PHP & MySql


tomms

Recommended Posts

Firstly, seasons greeting, hope everyone is closing out the year with style....

Down to business.... I am trying to create a real time form validator much like Ibegin ([url=http://www.ibegin.com/register/]http://www.ibegin.com/register/[/url]), if you notice once you fill out one of the inputs it will immidiatly give you either an "okay" or an error message next to it.

This is done with javascript and is pretty sraight forward, however the username and password are also checked against the database for duplicates (try to input "tomms" in username to see example).  This is done through file called "register.php. I do have a database set up, and it is populated by a similar member signup form.  However, i need some help writing the register.php file.  I do have some coding background but am a relative newbie to Php, any help would be appreicated.

The javascript....


[code]<script type="text/javascript">
function checkusername() {
var username = document.register.username.value;
if (username.length < 4 || username.length > 25) {
if (username.length < 4) {
document.getElementById('usernamecheck').innerHTML="<font style=\"color: red\">Username must be at least 4 characters</font>";
document.getElementById('username').style.border='red 1px solid';

} else {
document.getElementById('usernamecheck').innerHTML="<font style=\"color: red\">Username cannot be longer than 25 characters</font>";
document.getElementById('username').style.border='red 1px solid';
}
} else {
LoadIntoElementRegistration('register.php?action=check&username='+username,'usernamecheck','Checking ...', 'username');
}
}


function checkemail() {
var email = document.register.email.value;
if (email.length < 6 || email.length > 49) {
if (email.length < 6) {
document.getElementById('emailcheck').innerHTML="<font style=\"color: red\">Email is too short</font>";
document.getElementById('email').style.border='red 1px solid';
} else {
document.getElementById('emailcheck').innerHTML="<font style=\"color: red\">Email cannot be longer than 50 characters</font>";
document.getElementById('email').style.border='red 1px solid';
}
} else {
if (check_email(email)) {
LoadIntoElementRegistration('register.php?action=check&email='+email,'emailcheck','Checking ...','email');
} else {
document.getElementById('emailcheck').innerHTML="<font style=\"color: red\">Invalid email</font>";
document.getElementById('email').style.border='red 1px solid';
}
}
}

function check_email(e) { ok = "1234567890qwertyuiop[]asdfghjklzxcvbnm.@-_QWERTYUIOPASDFGHJKLZXCVBNM";  for(i=0; i < e.length ;i++){ if(ok.indexOf(e.charAt(i))<0){  return (false); } }  if (document.images) { re = /(@.*@)|(\.\.)|(^\.)|(^@)|(@$)|(\.$)|(@\.)/; re_two = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/; if (!e.match(re) && e.match(re_two)) { return (-1); }  }  }
</script>[/code]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.