From 8a5f9c02c615aa3897e16e2e04fecb6af258428f Mon Sep 17 00:00:00 2001 From: esensar Date: Sun, 22 May 2016 18:56:53 +0200 Subject: [PATCH] Country code validation --- add.php | 10 +++++++++- gori.php | 1 - header.php | 6 ++++++ js.js | 37 +++++++++++++++++++++++++++++++++++++ vijesti.csv | 2 ++ 5 files changed, 54 insertions(+), 2 deletions(-) diff --git a/add.php b/add.php index 1137c54..52fda2d 100644 --- a/add.php +++ b/add.php @@ -8,11 +8,19 @@ Slika link:

+
+
+
+


- + diff --git a/gori.php b/gori.php index de600ba..adca5e9 100644 --- a/gori.php +++ b/gori.php @@ -27,7 +27,6 @@ } } - print_r($slike); $time = date(DATE_ISO8601, strtotime("now")); $vijestiFile = $time.','.$slike.','.$vijest."\n".$vijestiFile; $vijestiFile = strip_tags($vijestiFile); diff --git a/header.php b/header.php index d15b4b0..4e44d7d 100644 --- a/header.php +++ b/header.php @@ -84,6 +84,12 @@ +
  • + +
  • diff --git a/js.js b/js.js index 04e8ba4..d971972 100644 --- a/js.js +++ b/js.js @@ -89,6 +89,43 @@ function onFilter(select) { } } +function validateCountry(countryCodeField) { + var ajax = new XMLHttpRequest(); + ajax.onreadystatechange = function() { + if(ajax.readyState == 4 && ajax.status == 200) { + var nekiResponseObjekatNesto = JSON.parse(ajax.response); + var nizko = []; + for(var i = 0; i < nekiResponseObjekatNesto.length; i++) { + nizko.push(nekiResponseObjekatNesto[i].callingCodes); + } + document.getElementById("brtel").data = nizko; + validatePhone(document.getElementById("brtel")); + } else if (ajax.readyState == 4) { + document.getElementById("brtel").style.backgroundColor = "red"; + document.getElementById("input").disabled = true; + } + } + ajax.open("GET", "https://restcountries.eu/rest/v1/alpha?codes=" + countryCodeField.value, true); + ajax.send(); +} + +function validatePhone(phoneField) { + var nizko = phoneField.data; + console.log(nizko); + if(!nizko) return; + for(var i = 0; i < nizko.length; i++) { + console.log(phoneField.value.indexOf(nizko[i])); + var index = phoneField.value.indexOf(nizko[i]); + if(index == 0 || index == 1) { + phoneField.style.backgroundColor = "white"; + document.getElementById("input").disabled = false; + return; + } + } + phoneField.style.backgroundColor = "red"; + document.getElementById("input").disabled = true; +} + function validateEmail(emailField) { var re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; if(re.test(emailField.value)) { diff --git a/vijesti.csv b/vijesti.csv index e69de29..b662a72 100644 --- a/vijesti.csv +++ b/vijesti.csv @@ -0,0 +1,2 @@ +2016-05-22T18:53:53+0200,,hljebovi +2016-05-22T18:52:02+0200,+38761553000,Kemicin telefon se nigdje u bazi ne spasava -- 2.31.1