Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript How-To
| Search | Today's Posts | Mark Forums Read
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 February 26th, 2004, 12:16 PM
Authorized User
 
Join Date: Jul 2003
Location: Urbana, IL, USA.
Posts: 41
Thanks: 0
Thanked 1 Time in 1 Post
Default checking for alpha in a string

{
  if (str.length != 3)
    return false;
  else if (str.charAt(0) != [a-z])
    return false;
  else if (!Is_Digit(str.charAt(1)))
    return false;
  else if (!Is_Digit(str.charAt(2)))
    return false;
  else return true;
}

The problem seems to be with the following line...comment it out and the rest
works.
else if (str.charAt(0) != [a-z])

The Following User Says Thank You to abbylee26 For This Useful Post:
amerifax (April 19th, 2011)
 
Old February 26th, 2004, 12:35 PM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Code:
(str.charAt(0) != [a-z])
I don't know where you got that expression from:)
One of a number of options would be:
Code:
if (str.charAt(0).replace(/[a-z]/g, "").length > 0)
or
Code:
if (/[^a-z]/.test(str.charAt(0))


--

Joe
The Following User Says Thank You to joefawcett For This Useful Post:
amerifax (April 19th, 2011)
 
Old April 12th, 2011, 06:44 PM
Registered User
Points: 38, Level: 1
Points: 38, Level: 1 Points: 38, Level: 1 Points: 38, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2007
Location: , , .
Posts: 9
Thanks: 6
Thanked 0 Times in 0 Posts
Default Trying to Learn

The only thing I understand is "If" and "Length". Could you give a brake down on what the code is doing?

Bob




Similar Threads
Thread Thread Starter Forum Replies Last Post
How to know data is numric or alpha numric dishant XSLT 1 September 26th, 2008 01:56 AM
DXImageTransform.Microsoft.Alpha doesnt validate crmpicco CSS Cascading Style Sheets 4 May 9th, 2006 05:11 AM
"Pause" Checking ... tonyrosen Excel VBA 2 November 23rd, 2005 11:02 AM
Checking for empty string richw32001 General .NET 1 August 8th, 2004 01:37 PM
checking string length for form validation Tachyon Beginning PHP 1 June 14th, 2004 08:16 PM





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