Zaloguj | Zarejestruj | FAQ
Anonymous

ASAP. How can I valid my postcode and telephone in this?

+ Odpowiedz

Posty: 2 Strona 1 z 1


ASAP. How can I valid my postcode and telephone in this?

przez Kakashi193 » Pt lut 07, 2014 6:22 am

<!DOCTYPE html>
<html>
<head>
<title> Register Form </title>
</head>

<body>
<script type='text/javascript'>

function getColour(inputName, type){
if(type){
document.getElementById(inputName).style.borderColor = "green";
return true;
}else{
document.getElementById(inputName).style.borderColor = "red";
return false;
}
}

//Functions to check text box if null value = red and value = green
function checkforblank(){
var errormessage= "";
var submit = true;
var nameErr = document.getElementById('nameErr');
var surnameErr= document.getElementById('surnameErr');
var streetaddErr= document.getElementById('streetaddErr');
var subErr= document.getElementById('subErr');
var stateErr= document.getElementById('stateErr');
var postcodeErr= document.getElementById('postcodeErr');
var telephoneErr= document.getElementById('telephoneErr');
var emailErr= document.getElementById('emailErr');

if(document.getElementById('name').value == ""){
nameErr.innerHTML = "Please Enter Your Name\n";
submit = getColour("name", false);
}else{
nameErr.innerHTML = '';
getColour("name", true);
}

if(document.getElementById('surname').value == ""){
surnameErr.innerHTML = "Please Enter Your Surname\n";
submit = getColour("surname", false);
}else{
surnameErr.innerHTML = '';
getColour("surname", true);
}

if(document.getElementById('streetadd').value == ""){
streetaddErr.innerHTML = "Please Enter Your Street Address\n";
submit = getColour("streetadd", false);
}else{
streetaddErr.innerHTML = '';
getColour("streetadd", true);
}

if(document.getElementById('sub').value == ""){
subErr.innerHTML = "Please Enter Your Surburb\n";
submit = getColour("sub", false);
}else{
subErr.innerHTML = '';
getColour("sub", true)
}

if(document.getElementById('state').value == "select"){
stateErr.innerHTML = "Please Select Your State\n";
submit = getColour("state", false);
}else{
stateErr.innerHTML = '';
getColour("state", true)
}

if(document.getElementById('postcode').value == ""){
postcodeErr.innerHTML = "Please Enter Your Postcode\n"
submit = getColour("postcode", false);
}else{
postcodeErr.innerHTML = '';
getColour("postcode", true);
}

if(document.getElementById('telephone').value == ""){
telephoneErr.innerHTML = "Please Enter Your Telephone Number\n"
submit = getColour("telephone", false);
}else{
telephoneErr.innerHTML = '';
getColour("telephone", true);
}

if(document.getElementById('email').value == ""){
emailErr.innerHTML = "Please Enter Valid Email\n"
submit = getColour("email", false);
}else{
emailErr.innerHTML = '';
getColour("email", true);
}

return submit;

}
</script>
<h1>Register Form</h1>
<form action="register.php" method="post" onsubmit="return checkforblank()">
<!--Input name-->
<table>
<tr>
<td> First Name *: </br> <input type="text" id="name" name= "name" maxlength="20"/> </td>
<td> </br> <p style="margin:10px; height:10px; color:red;" id="nameErr"></p> </td>
</tr>

<!--Input Surname-->
<tr>
<td> Last Name *: </br> <input type="text" id="surname" name= "surname" maxlength="30"/> </td>
<td> </br> <p style="margin:10px; height:10px; color:red;" id="surnameErr"></p> </td>
</tr>

<!--Input Street Address-->
<tr>
<td> Street Address *:</br> <input type="text" id="streetadd" name= "streetadd" maxlength="50"/> </td>
<td> </br> <p style="margin:10px; height:10px; color:red;" id="streetaddErr"></p> </td>
</tr>

<!--Input Suburb-->
<tr>
<td> Suburb *:</br> <input type="text" id="sub" name= "sub" maxlength="15"/> </td>
<td> </br> <p style="margin:10px; height:10px; color:red;" id="subErr"></p> </td>
</tr>

<!--State select option-->

<tr>
<td> State *:</br> <select id="state" name= "state">

<option value="select">Select</option>
<option value="NT">NT</option>
<option value="QLD">QLD</option>
<option value="NSW">NSW</option>
<option value="ACT">ACT</option>
<option value="VIC">VIC</option>
<option value="WA">WA</option>
<option value="SA">SA</option>
<option value="TAS">TAS</option>
</select>
</td>
<td> </br> <p style="margin:10px; height:10px; color:red;" id="stateErr"></p> </td>
</tr>

<!--Input Post Code-->
<tr>
<td> Post Code *:</br> <input type="text" id="postcode" name= "postcode" maxlength="4"/> </td>
<td> </br> <p style="margin:10px; height:10px; color:red;" id="postcodeErr"></p> </td>
</tr>

<!--Input Telephone-->
<tr>
<td> Telephone:</br> <input type="text" id="telephone" name= "telephone" maxlength="10"/> </td>
<td> </br> <p style="margin:10px; height:10px; color:red;" id="telephoneErr"></p> </td>
</tr>

<!--Input Email-->
<tr>
<td> Email *:</br> <input type="email" id="email" name= "email"/> </br> </td>
<td> </br> <p style="margin:10px; height:10px; color:red;" id="emailErr"></p> </td>
</tr>
</table>
<!--Register submit button-->
<br> <input type="submit" value="Register"/>


</form>

</body>


</html>
Avatar użytkownika

Kakashi193

  • Posty: 2
  • Dołączył(a): Wt lut 04, 2014 4:01 am

Re: ASAP. How can I valid my postcode and telephone in this?

przez XainPro » Pt lut 07, 2014 7:40 am

<!DOCTYPE html>
<html>
<head>
<title> Register Form </title>
</head>

<body>
<script type='text/javascript'>

function getColour(inputName, type){
if(type){
document.getElementById(inputName).style.borderColor = "green";
return true;
}else{
document.getElementById(inputName).style.borderColor = "red";
return false;
}
}

//Functions to check text box if null value = red and value = green
function checkforblank(){
var errormessage= "";
var submit = true;
var nameErr = document.getElementById('nameErr');
var surnameErr= document.getElementById('surnameErr');
var streetaddErr= document.getElementById('streetaddErr');
var subErr= document.getElementById('subErr');
var stateErr= document.getElementById('stateErr');
var postcodeErr= document.getElementById('postcodeErr');
var telephoneErr= document.getElementById('telephoneErr');
var emailErr= document.getElementById('emailErr');

if(document.getElementById('name').value == ""){
nameErr.innerHTML = "Please Enter Your Name\n";
submit = getColour("name", false);
}else{
nameErr.innerHTML = '';
getColour("name", true);
}

if(document.getElementById('surname').value == ""){
surnameErr.innerHTML = "Please Enter Your Surname\n";
submit = getColour("surname", false);
}else{
surnameErr.innerHTML = '';
getColour("surname", true);
}

if(document.getElementById('streetadd').value == ""){
streetaddErr.innerHTML = "Please Enter Your Street Address\n";
submit = getColour("streetadd", false);
}else{
streetaddErr.innerHTML = '';
getColour("streetadd", true);
}

if(document.getElementById('sub').value == ""){
subErr.innerHTML = "Please Enter Your Surburb\n";
submit = getColour("sub", false);
}else{
subErr.innerHTML = '';
getColour("sub", true)
}

if(document.getElementById('state').value == "select"){
stateErr.innerHTML = "Please Select Your State\n";
submit = getColour("state", false);
}else{
stateErr.innerHTML = '';
getColour("state", true)
}
var postcodeRegEx = /[A-Z]{1,2}[0-9]{1,2} ?[0-9][A-Z]{2}/i;
if(!postcodeRegEx.test(document.getElementById('postcode').value)){
postcodeErr.innerHTML = "Please Enter Your Postcode\n"
submit = getColour("postcode", false);
}else{
postcodeErr.innerHTML = '';
getColour("postcode", true);
}

var PhoneRegex = /^\d{10}$/g;
if(!PhoneRegex.test(document.getElementById('telephone').value)){
telephoneErr.innerHTML = "Please Enter Your Telephone Number\n It should be 10 numerical digits"
submit = getColour("telephone", false);
}else{
telephoneErr.innerHTML = '';
getColour("telephone", true);
}

if(document.getElementById('email').value == ""){
emailErr.innerHTML = "Please Enter Valid Email\n"
submit = getColour("email", false);
}else{
emailErr.innerHTML = '';
getColour("email", true);
}

return submit;

}
</script>
<h1>Register Form</h1>
<form action="register.php" method="post" onsubmit="return checkforblank()">
<!--Input name-->
<table>
<tr>
<td> First Name *: </br> <input type="text" id="name" name= "name" maxlength="20"/> </td>
<td> </br> <p style="margin:10px; height:10px; color:red;" id="nameErr"></p> </td>
</tr>

<!--Input Surname-->
<tr>
<td> Last Name *: </br> <input type="text" id="surname" name= "surname" maxlength="30"/> </td>
<td> </br> <p style="margin:10px; height:10px; color:red;" id="surnameErr"></p> </td>
</tr>

<!--Input Street Address-->
<tr>
<td> Street Address *:</br> <input type="text" id="streetadd" name= "streetadd" maxlength="50"/> </td>
<td> </br> <p style="margin:10px; height:10px; color:red;" id="streetaddErr"></p> </td>
</tr>

<!--Input Suburb-->
<tr>
<td> Suburb *:</br> <input type="text" id="sub" name= "sub" maxlength="15"/> </td>
<td> </br> <p style="margin:10px; height:10px; color:red;" id="subErr"></p> </td>
</tr>

<!--State select option-->

<tr>
<td> State *:</br> <select id="state" name= "state">

<option value="select">Select</option>
<option value="NT">NT</option>
<option value="QLD">QLD</option>
<option value="NSW">NSW</option>
<option value="ACT">ACT</option>
<option value="VIC">VIC</option>
<option value="WA">WA</option>
<option value="SA">SA</option>
<option value="TAS">TAS</option>
</select>
</td>
<td> </br> <p style="margin:10px; height:10px; color:red;" id="stateErr"></p> </td>
</tr>

<!--Input Post Code-->
<tr>
<td> Post Code *:</br> <input type="text" id="postcode" name= "postcode" maxlength="4"/> </td>
<td> </br> <p style="margin:10px; height:10px; color:red;" id="postcodeErr"></p> </td>
</tr>

<!--Input Telephone-->
<tr>
<td> Telephone:</br> <input type="text" id="telephone" name= "telephone" maxlength="10"/> </td>
<td> </br> <p style="margin:10px; height:10px; color:red;" id="telephoneErr"></p> </td>
</tr>

<!--Input Email-->
<tr>
<td> Email *:</br> <input type="email" id="email" name= "email"/> </br> </td>
<td> </br> <p style="margin:10px; height:10px; color:red;" id="emailErr"></p> </td>
</tr>
</table>
<!--Register submit button-->
<br> <input type="submit" value="Register"/>


</form>

</body>


</html>
Avatar użytkownika

XainPro

  • Posty: 3933
  • Dołączył(a): Pt lut 17, 2012 8:10 pm


+ Odpowiedz

Strona 1 z 1