|
|
|
|
|
|
| |
Sometimes it becomes necessary to process user input client side. It saves the user a lot of time if he/she is notified of errors in his/her errors before submitting the form. This example contains two functions for validating email addresses and urls.
| <!doctype html public "-//w3c//dtd html 4.01 transitional//en">
<html>
<head>
<title>JavaScrip URL & Email Validation</title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<script type="text/javascript">
<!--
function isValidURL(url){
var RegExp = /^(([\w]+:)?\/\/)?(([\d\w]|%[a-fA-f\d]{2,2})+(:([\d\w]|%[a-fA-f\d]{2,2})+)?@)?([\d\w][-\d\w]{0,253}[\d\w]\.)+[\w]{2,4}(:[\d]+)?(\/([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)*(\?(&?([-+_~.\d\w]|%[a-fA-f\d]{2,2})=?)*)?(#([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)?$/;
if(RegExp.test(url)){
return true;
}else{
return false;
}
}
function isValidEmail(email){
var RegExp = /^((([a-z]|[0-9]|!|#|$|%|&|'|\*|\+|\-|\/|=|\?|\^|_|`|\{|\||\}|~)+(\.([a-z]|[0-9]|!|#|$|%|&|'|\*|\+|\-|\/|=|\?|\^|_|`|\{|\||\}|~)+)*)@((((([a-z]|[0-9])([a-z]|[0-9]|\-){0,61}([a-z]|[0-9])\.))*([a-z]|[0-9])([a-z]|[0-9]|\-){0,61}([a-z]|[0-9])\.)[\w]{2,4}|(((([0-9]){1,3}\.){3}([0-9]){1,3}))|(\[((([0-9]){1,3}\.){3}([0-9]){1,3})\])))$/
if(RegExp.test(email)){
return true;
}else{
return false;
}
}
function checkField(){
var frm = document.frmValidate, error = "";
if(!isValidURL(frm.url.value)){
error += "Please enter a valid URL\n";
}
if(!isValidEmail(frm.email.value)){
error += 'Please enter a valid Email\n';
}
if(error != ""){
alert(error);
return false;
}else{
return true;
}
}
//-->
</script>
</head>
<body>
<table height="100%" width="100%">
<tr><td>
<center><form name="frmValidate" onsubmit="return checkField()">
<table cellspacing="2" cellpadding="5" border="1">
<tr><td>Enter Valid URL : </td>
<td><input type="text" name="url"></td></tr>
<tr><td>Enter Valid Email : </td>
<td><input type="text" name="email"></td></tr>
<tr><td colspan="2"><center><input type="submit" value="Check"></center></td></tr>
</table>
</form></center>
</td></tr></table>
</body>
</html> | | |
|
| Adding a Filter to a Text Element Categories : Java Script, Data Validation, Form Processing | | | Form Processing : with alert Highlight field name which is not filled by user Categories : Java Script, Form Processing, Data Validation, Beginner Guides, Web Design | | | Db_lib - practical example usage of database abstraction and form validation.
Categories : PHP, Form Processing, PHP Classes, Data Validation, Beginner Guides | | | Validating a URL with JavaScript RegExp Categories : Java Script, Data Validation, Beginner Guides | | | PHPRecommend v1.0 - "Recommend this page to a friend" script written in
PHP. Easy to install Categories : PHP, URLs, Complete Programs, Email, Site Planning | | | Show hide table rows to make dynamic forms Categories : Beginner Guides, Java Script, Form Processing, HTTP | | | Form Validation Using PHP to highlight non valid fields Categories : PHP, Form Processing, Data Validation, Beginner Guides | | | Form validations using javascript and including all validations in one message Categories : HTML and PHP, Java Script, Form Processing | | | Validator - A PHP class that can can be used for validating Email IDs and Dates Categories : PHP, PHP Classes, Data Validation, Email, Date Time | | | Upload any fixed type of files, control file type through javascript and encrypt filename using php so file not get overwrite Categories : PHP, Java Script, Functions, PHP References, Form Processing | | | Conditional Check - a script that allows a user to submit a form only if the user check a checkbox. Categories : HTML, Java Script, Form Processing, Beginner Guides | | | cPanel Email Accounts Creator Categories : PHP, PHP Classes, Email, Form Processing, Web Services | | | PHP and javascript mouseover, mouseout, and mousedown events Categories : PHP, Java Script, Form Processing, Beginner Guides | | | Balance values between two list boxes. Change the value of list box A acording to the value in list box B and vice versa using Javasvript. Categories : Java Script, Form Processing | | | send_mail function to defeat Header Injection Hacking/Spamming Categories : PHP, Email, Form Processing, Security | |
|
|
|