PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old October 16th, 2012, 03:18 AM
rageedi rageedi is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2012
Posts: 13 rageedi User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 22 m 57 sec
Reputation Power: 0
Regular expression problem

hi,
i am struggling to do basic regular expression that matches
"A1234567", must starts with A and is 8 characters long,
this is what i have so far:

PHP Code:
<?php
$reg1 
"/^[A]+[0-9]{8}/";
$lstring "A1234567";
if (
preg_match($reg1,$lstring))
{
    echo 
"yes";
}
else
{    
    echo 
"no";
}
?>



can some one please help

Reply With Quote
  #2  
Old October 16th, 2012, 04:24 AM
Jacques3 Jacques3 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 57 Jacques3 User rank is Sergeant (500 - 2000 Reputation Level)Jacques3 User rank is Sergeant (500 - 2000 Reputation Level)Jacques3 User rank is Sergeant (500 - 2000 Reputation Level)Jacques3 User rank is Sergeant (500 - 2000 Reputation Level)Jacques3 User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 1 Day 10 h 6 m 14 sec
Reputation Power: 11
Hi,

I think there's a general misunderstanding regarding the regex syntax. What you've wrote down means:

a string starting with at least one A (can be more) followed by 8 digits and after that an abritrary number of characters

If you want a string starting with a single A followed by exactly 7 digits and nothing else, that would be

/^A\d{7}$/

You cannot set the string length with regexes, only the count of a specific expression.

Reply With Quote
  #3  
Old October 18th, 2012, 02:59 AM
rageedi rageedi is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2012
Posts: 13 rageedi User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 22 m 57 sec
Reputation Power: 0
thank you so much.

is there another way/s of writting that expression?

Reply With Quote
  #4  
Old October 18th, 2012, 03:05 AM
Jacques3 Jacques3 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 57 Jacques3 User rank is Sergeant (500 - 2000 Reputation Level)Jacques3 User rank is Sergeant (500 - 2000 Reputation Level)Jacques3 User rank is Sergeant (500 - 2000 Reputation Level)Jacques3 User rank is Sergeant (500 - 2000 Reputation Level)Jacques3 User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 1 Day 10 h 6 m 14 sec
Reputation Power: 11
Quote:
Originally Posted by rageedi
is there another way/s of writting that expression?


What do you mean? Of course you can make it longer, for example by replacing the \d with [0-9] or by actually writing down all 7 digits. But this is the shortest and most clean way.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > Regular expression problem

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap