daily pastebin goal
50%
SHARE
TWEET

Untitled

a guest Jul 21st, 2017 84 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function getHTTPObject(){
  2.     if (window.ActiveXObject)
  3.     return new ActiveXObject("Microsoft.XMLHTTP");
  4.     else if (window.XMLHttpRequest)
  5.     return new XMLHttpRequest();
  6.     else {
  7.     alert("Your browser is ancient.  Get Chrome.");
  8.     return null;
  9.     }
  10. }
  11.  
  12. function checkUsername(){
  13.     if (document.getElementById('txtUsername').value.length == 0) {
  14.     document.getElementById('tdUsername').innerHTML = '';
  15.     }
  16.     else if (document.getElementById('txtUsername').value.length < 4) {
  17.     document.getElementById('tdUsername').innerHTML = '<img src="images/cross.png" alt="Invalid" />';
  18.     } else {
  19.     if (isAlphaNumeric(document.getElementById('txtUsername').value) == true) {
  20.         httpObject = getHTTPObject();
  21.         if (httpObject != null) {
  22.         httpObject.open("GET", "backend/register.php?action=checkUsername&username=" + document.getElementById('txtUsername').value, true);
  23.         httpObject.send(null);
  24.         httpObject.onreadystatechange = setOutput;
  25.         }
  26.     } else {
  27.         document.getElementById('tdUsername').innerHTML = '<img src="images/cross.png" alt="Invalid" />';
  28.     }
  29.     }
  30. }
  31.  
  32. function checkPassword() {
  33.     if (document.getElementById('txtPassword').value.length == 0) {
  34.     document.getElementById('tdPassword').innerHTML = '';
  35.     }
  36.     else if (document.getElementById('txtPassword').value.length < 4) {
  37.     document.getElementById('tdPassword').innerHTML = '<img src="images/cross.png" alt="Invalid" />';
  38.     } else {
  39.     document.getElementById('tdPassword').innerHTML = '<img src="images/tick.png" alt="Valid" />';
  40.     }
  41. }
  42.  
  43. function checkPasswordMatch() {
  44.     if (document.getElementById('txtPasswordConfirm').value.length == 0) {
  45.     document.getElementById('tdPasswordConfirm').innerHTML = '';
  46.     }
  47.     else if (document.getElementById('txtPasswordConfirm').value == document.getElementById('txtPassword').value) {
  48.     document.getElementById('tdPasswordConfirm').innerHTML = '<img src="images/tick.png" alt="Valid" />';
  49.     } else {
  50.     document.getElementById('tdPasswordConfirm').innerHTML = '<img src="images/cross.png" alt="Invalid" />';
  51.     }
  52. }
  53.  
  54. function checkEmail() {
  55.     if (document.getElementById('txtEmail').value.length == 0) {
  56.     document.getElementById('tdEmail').innerHTML = '';
  57.     }
  58.     else if (isEmailAddress(document.getElementById('txtEmail').value) == true) {
  59.     document.getElementById('tdEmail').innerHTML = '<img src="images/tick.png" alt="Valid" />';
  60.     } else {
  61.     document.getElementById('tdEmail').innerHTML = '<img src="images/cross.png" alt="Invalid" />';
  62.     }
  63. }
  64.  
  65. function registerUser() {
  66.     httpObject = getHTTPObject();
  67.     if (httpObject != null) {
  68.     httpObject.open("GET", "backend/register.php?action=registerUser&username=" + document.getElementById('txtUsername').value + "&password=" + document.getElementById('txtPassword').value + "&emailAddress=" + document.getElementById('txtEmail').value, true);
  69.     httpObject.send(null);
  70.     httpObject.onreadystatechange = handleRegistration;
  71.     }
  72. }
  73.  
  74. function setOutput() {
  75.     if(httpObject.readyState == 4) {
  76.     if (httpObject.responseText == '1') {
  77.         document.getElementById('tdUsername').innerHTML = '<img src="images/tick.png" alt="Valid" />';
  78.     } else {
  79.         document.getElementById('tdUsername').innerHTML = '<img src="images/cross.png" alt="Invalid" />';
  80.     }
  81.    
  82.     }
  83. }
  84.  
  85. function handleRegistration() {
  86.     if(httpObject.readyState == 4) {
  87.     if (httpObject.responseText == '1') {
  88.         window.location = "/register2.php";
  89.     } else if (httpObject.responseText == '0') {
  90.         document.getElementById('tdUsername').innerHTML = 'Registration failed.';
  91.     } else {
  92.         document.getElementById('tdUsername').innerHTML = 'Server error.';
  93.     }
  94.     }
  95. }
  96.  
  97. function isAlphaNumeric(val) {
  98.     if (val.match(/^[a-zA-Z0-9]+$/)) {
  99.     return true;
  100.     } else {
  101.     return false;
  102.     }
  103. }
  104.  
  105. function isEmailAddress(val) {
  106.     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])?/)) {
  107.     return true;
  108.     } else {
  109.     return false;
  110.     }
  111. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top