Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function getHTTPObject(){
- if (window.ActiveXObject)
- return new ActiveXObject("Microsoft.XMLHTTP");
- else if (window.XMLHttpRequest)
- return new XMLHttpRequest();
- else {
- alert("Your browser is ancient. Get Chrome.");
- return null;
- }
- }
- function checkUsername(){
- if (document.getElementById('txtUsername').value.length == 0) {
- document.getElementById('tdUsername').innerHTML = '';
- }
- else if (document.getElementById('txtUsername').value.length < 4) {
- document.getElementById('tdUsername').innerHTML = '<img src="images/cross.png" alt="Invalid" />';
- } else {
- if (isAlphaNumeric(document.getElementById('txtUsername').value) == true) {
- httpObject = getHTTPObject();
- if (httpObject != null) {
- httpObject.open("GET", "backend/register.php?action=checkUsername&username=" + document.getElementById('txtUsername').value, true);
- httpObject.send(null);
- httpObject.onreadystatechange = setOutput;
- }
- } else {
- document.getElementById('tdUsername').innerHTML = '<img src="images/cross.png" alt="Invalid" />';
- }
- }
- }
- function checkPassword() {
- if (document.getElementById('txtPassword').value.length == 0) {
- document.getElementById('tdPassword').innerHTML = '';
- }
- else if (document.getElementById('txtPassword').value.length < 4) {
- document.getElementById('tdPassword').innerHTML = '<img src="images/cross.png" alt="Invalid" />';
- } else {
- document.getElementById('tdPassword').innerHTML = '<img src="images/tick.png" alt="Valid" />';
- }
- }
- function checkPasswordMatch() {
- if (document.getElementById('txtPasswordConfirm').value.length == 0) {
- document.getElementById('tdPasswordConfirm').innerHTML = '';
- }
- else if (document.getElementById('txtPasswordConfirm').value == document.getElementById('txtPassword').value) {
- document.getElementById('tdPasswordConfirm').innerHTML = '<img src="images/tick.png" alt="Valid" />';
- } else {
- document.getElementById('tdPasswordConfirm').innerHTML = '<img src="images/cross.png" alt="Invalid" />';
- }
- }
- function checkEmail() {
- if (document.getElementById('txtEmail').value.length == 0) {
- document.getElementById('tdEmail').innerHTML = '';
- }
- else if (isEmailAddress(document.getElementById('txtEmail').value) == true) {
- document.getElementById('tdEmail').innerHTML = '<img src="images/tick.png" alt="Valid" />';
- } else {
- document.getElementById('tdEmail').innerHTML = '<img src="images/cross.png" alt="Invalid" />';
- }
- }
- function registerUser() {
- httpObject = getHTTPObject();
- if (httpObject != null) {
- httpObject.open("GET", "backend/register.php?action=registerUser&username=" + document.getElementById('txtUsername').value + "&password=" + document.getElementById('txtPassword').value + "&emailAddress=" + document.getElementById('txtEmail').value, true);
- httpObject.send(null);
- httpObject.onreadystatechange = handleRegistration;
- }
- }
- function setOutput() {
- if(httpObject.readyState == 4) {
- if (httpObject.responseText == '1') {
- document.getElementById('tdUsername').innerHTML = '<img src="images/tick.png" alt="Valid" />';
- } else {
- document.getElementById('tdUsername').innerHTML = '<img src="images/cross.png" alt="Invalid" />';
- }
- }
- }
- function handleRegistration() {
- if(httpObject.readyState == 4) {
- if (httpObject.responseText == '1') {
- window.location = "/register2.php";
- } else if (httpObject.responseText == '0') {
- document.getElementById('tdUsername').innerHTML = 'Registration failed.';
- } else {
- document.getElementById('tdUsername').innerHTML = 'Server error.';
- }
- }
- }
- function isAlphaNumeric(val) {
- if (val.match(/^[a-zA-Z0-9]+$/)) {
- return true;
- } else {
- return false;
- }
- }
- function isEmailAddress(val) {
- if (val.match(/[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?/)) {
- return true;
- } else {
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement