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 (http://www.ibegin.com/register/), 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....
<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>