Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript How-To
|
Javascript How-To Ask your "How do I do this with Javascript?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 10th, 2010, 09:24 AM
Authorized User
 
Join Date: Jan 2010
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to elizas
Default Numeric validation using Javascript

Basicallly When we trying to validate a form some time we need numeric validation for textbox.

We can validate textbox by onkeypress event of the control By checking whether the keycode of the key pressed as the user types falls within the range of the number keys 48-57(i.e 0-9 and '.') ,if not belong to that range it will return false then it will disable the keypress action
function NumericValidation(eventObj)
{
var keycode;

if(eventObj.keyCode) //For IE
keycode = eventObj.keyCode;
else if(eventObj.Which)
keycode = eventObj.Which; // For FireFox
else
keycode = eventObj.charCode; // Other Browser

Eliza
__________________
Cheers,
Eliza

Mindfire: India's Only Company to be both Apple Premier & Microsoft Gold certified.
 
Old July 23rd, 2010, 11:13 AM
Registered User
 
Join Date: Sep 2009
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default HTML in Dynamic Table cells

Hi All,

I tried to add links to open local xml files in browser in a dynamic table cells. I need help. I tried all ways but I think I miss something.
I can open them without table just by document.write(xmlfile location).
Here is my code. please help.
function showResultsTable(searched, srchedname) {
// get the reference for the body
var mybody = document.getElementsByTagName("body")[0];

// creates a <table> element and a <tbody> element
mytable = document.createElement("table");
mytable.setAttribute('id', 'resulttable');
mytablebody = document.createElement("tbody");

// creating all cells
var mycurrent_cell = new Array();

for(var j = 0; j < srchedname.length; j++) {
// creates a <tr> element
mycurrent_row = document.createElement("tr");

mycurrent_cell[0] = document.createElement("td");
currenttext = document.createTextNode(j);
mycurrent_cell[0].appendChild(currenttext);
mycurrent_row.appendChild(mycurrent_cell[0]);


mycurrent_cell[1] = document.createElement("td");
link = document.createElement("a");
link.name = ""+srchedname[j]);
link.href = "C:\\AAA\\TestCasesList.xml";
mycurrent_cell[1].appendChild(link);
mycurrent_row.appendChild(mycurrent_cell[1]);

mycurrent_cell[2] = document.createElement("td");
currenttext = document.createTextNode(searched[j]);
mycurrent_cell[2].appendChild(currenttext);
mycurrent_row.appendChild(mycurrent_cell[2]);

// appends the row <tr> into <tbody>
mytablebody.appendChild(mycurrent_row);
}
// appends <tbody> into <table>
mytable.appendChild(mytablebody);
// appends <table> into <body>
mybody.appendChild(mytable);
// sets the border attribute of mytable to 2;
mytable.setAttribute("border", "2");

}
 
Old October 30th, 2011, 07:24 AM
Registered User
 
Join Date: Oct 2011
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Lightbulb Why validate if it's only a number?

Hi all!
It's my first post here. I have a better way of validation. Why not validate the phone number's country and location too?
I wrote a blog on this.
validate phone number location using javascript

When this is applied, you can not only check if the input looks like a phone number, but you can also check which country does the number belong to. For USA numbers, you can even check the state of the number. I hope it helps everybody :-)





Similar Threads
Thread Thread Starter Forum Replies Last Post
Getting mobile phone number yukijocelyn C# 2005 0 May 28th, 2008 11:43 PM
Mobile number Validation dharmeshtandel C# 2 April 23rd, 2008 01:12 PM
phone number validation debjanib ASP.NET 1.0 and 1.1 Professional 0 June 6th, 2006 12:01 PM
reformat phone number netcrawler Classic ASP Databases 1 November 3rd, 2004 09:01 PM
Phone Number validation help. mar0364 Classic ASP Basics 1 July 25th, 2004 06:39 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.