Javascript
jQuery |
Phone number Validation script
<html>
<head>
<title>title</title>
<script language = "Javascript">
/**
* DHTML phone number validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
*/
// Declaring required variables
var digits = "0123456789";
// non-digit characters which are allowed in phone numbers
var phoneNumberDelimiters = "()- ";
// characters which are allowed in international phone numbers
// (a leading + is OK)
var validWorldPhoneChars = phoneNumberDelimiters + "+";
// Minimum no of digits in an international phone no.
var minDigitsInIPhoneNumber = 10;
function isInteger(s)
{ var i;
for (i = 0; i < s.length; i++)
{
// Check that current character is number.
var c = s.charAt(i);
if (((c < "0") || (c > "9"))) return false;
}
// All characters are numbers.
return true;
}
function trim(s)
{ var i;
var returnString = "";
// Search through string's characters one by one.
// If character is not a whitespace, append to returnString.
for (i = 0; i < s.length; i++)
{
// Check that current character isn't whitespace.
var c = s.charAt(i);
if (c != " ") returnString += c;
}
return returnString;
}
function stripCharsInBag(s, bag)
{ var i;
var returnString = "";
// Search through string's characters one by one.
// If character is not in bag, append to returnString.
for (i = 0; i < s.length; i++)
{
// Check that current character isn't whitespace.
var c = s.charAt(i);
if (bag.indexOf(c) == -1) returnString += c;
}
return returnString;
}
function checkInternationalPhone(strPhone){
var bracket=3
strPhone=trim(strPhone)
if(strPhone.indexOf("+")>1) return false
if(strPhone.indexOf("-")!=-1)bracket=bracket+1
if(strPhone.indexOf("(")!=-1 && strPhone.indexOf("(")>bracket)return false
var brchr=strPhone.indexOf("(")
if(strPhone.indexOf("(")!=-1 && strPhone.charAt(brchr+2)!=")")return false
if(strPhone.indexOf("(")==-1 && strPhone.indexOf(")")!=-1)return false
s=stripCharsInBag(strPhone,validWorldPhoneChars);
return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
}
function ValidateForm(){
var Phone=document.frmSample.txtPhone
if ((Phone.value==null)||(Phone.value=="")){
alert("Please Enter your Phone Number")
Phone.focus()
return false
}
if (checkInternationalPhone(Phone.value)==false){
alert("Please Enter a Valid Phone Number")
Phone.value=""
Phone.focus()
return false
}
return true
}
</script>
</head>
<body>
<form name="frmSample" method="post" action="#" onSubmit="return ValidateForm()">
<p>Enter a phone number : <input type="text" name="txtPhone"></p>
<p><input type="submit" name="Submit" value="Submit"></p>
</form>
</body>
</html>
Watermark using jQuery
found here: http://cysemic.com/2008/12/very-simple-textbox-watermark-using-jquery/
If you haven’t heard about JQuery by now, I strongly suggest you go check it out. It is a very powerful cross-browser JavaScript library that simplifies a lot of the script I have to write, and even more interesting is the fact that Microsoft is going to start distributing it as well with Visual Studio and ASP .NET MVC. I had a post very similar to this one on my blog before, but since it got lost, I decided to go ahead and post it again, slightly improved over the last version.
The idea here is to be simple, and do this in just a few lines of JavaScript. I’m not here to teach all of the intricacies of JQuery, as that can best be explained by the documentation on their website.
I’ll start by displaying the HTML element that we will be manipulating:
The CSS class on that element is really simple and defines the look of the textbox when the watermark is active:
.watermarkOn {
color: #CCCCCC;
font-style: italic;
}
</style>
Now to write the script that does all of the action. I will assume that you’ve already set up the JavaScript include for JQuery on the page:
// Define what happens when the textbox comes under focus
// Remove the watermark class and clear the box
$("#textBox1").focus(function() {
$(this).filter(function() {
// We only want this to apply if there's not
// something actually entered
return $(this).val() == "" || $(this).val() == "Type here"
}).removeClass("watermarkOn").val("");
});
// Define what happens when the textbox loses focus
// Add the watermark class and default text
$("#textBox1").blur(function() {
$(this).filter(function() {
// We only want this to apply if there's not
// something actually entered
return $(this).val() == ""
}).addClass("watermarkOn").val("Type here");
});
});
And that’s all there is to it! If you’re using this on your site, you’ll probably want to do a bit more customization and such, but these are the basics. I skimmed over a lot of the fine details, I know, but there really isn’t much more to it than this.
All of the HTML Named Colors
http://www.crockford.com/wrrrld/color.html
Local link to script: color.html.txt
List of files attached to the group Group? \\
- color.html.txt ... 4,635 bytes ... November 12, 2011, at 04:04 PM
- DraggableImageBoxesGrid.zip ... 324,297 bytes ... October 16, 2011, at 05:32 PM