Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
BOOK: Beginning Regular Expressions
This is the forum to discuss the Wrox book Beginning Regular Expressions by Andrew Watt; ISBN: 9780764574894
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning Regular Expressions 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
  #1 (permalink)  
Old November 8th, 2008, 10:13 AM
Registered User
 
Join Date: Nov 2008
Location: Chisinau, Moldova, Moldova.
Posts: 5
Thanks: 2
Thanked 0 Times in 0 Posts
Send a message via ICQ to SKYDOS
Default Checking an ICQ number

i have a question...
i wrote this script on J to check user's ICQ number...
where is my mistake?

if an ICQ number is equal to '646546545' the result is 'true', and the same result is when icq = 'a646546545'

<script type="text/javascript" language="javascript">
var ICQ = "a646546545";

var oRegExp = new RegExp ("[0-9]{9}");

document.write (oRegExp.test (ICQ));
</script>

thank's

don't worry, be programmer
  #2 (permalink)  
Old November 9th, 2008, 02:01 PM
Registered User
 
Join Date: Nov 2008
Location: Chisinau, Moldova, Moldova.
Posts: 5
Thanks: 2
Thanked 0 Times in 0 Posts
Send a message via ICQ to SKYDOS
Default

:(hayyyy!!! anybody!!

don't worry, be programmer
  #3 (permalink)  
Old November 9th, 2008, 03:48 PM
Friend of Wrox
 
Join Date: Jun 2008
Location: Snohomish, WA, USA
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

You need start and end markers:

var oRegExp = /^\d{9,9}$/

The ^ means "match the beginning of the text" and the $ means "match the end of the text."

Your expression was just asking for 9 digits *ANYWHERE* in the text. So it would have said TRUE even for
     abcdefghijklmn111222333opqrstuvwxyz
  #4 (permalink)  
Old November 9th, 2008, 03:55 PM
Registered User
 
Join Date: Nov 2008
Location: Chisinau, Moldova, Moldova.
Posts: 5
Thanks: 2
Thanked 0 Times in 0 Posts
Send a message via ICQ to SKYDOS
Default

Quote:
quote:Originally posted by Old Pedant
 You need start and end markers:

var oRegExp = /^\d{9,9}$/

The ^ means "match the beginning of the text" and the $ means "match the end of the text."

Your expression was just asking for 9 digits *ANYWHERE* in the text. So it would have said TRUE even for
     abcdefghijklmn111222333opqrstuvwxyz
thank's!!!

don't worry, be programmer


Similar Threads
Thread Thread Starter Forum Replies Last Post
Validation For Phone Number and Mobile Number dhruthi.ram99 Javascript How-To 12 October 30th, 2011 07:24 AM
Checking a ComboBox Salte C# 2 November 30th, 2004 05:49 PM
Checking for upper,lower case, number and symbol dumbdumb SQL Server 2000 1 March 18th, 2004 03:51 AM
ICQ or MSN Messenger controls? tonyh Beginning VB 6 1 November 10th, 2003 12:45 PM
Checking for a number aware Classic ASP Basics 5 June 5th, 2003 09:57 PM





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