Jump to content

Search the Community

Showing results for tags 'regex'.



More search options

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Welcome to PHP Freaks
    • Announcements
    • Introductions
  • PHP Coding
    • PHP Coding Help
    • Regex Help
    • Third Party Scripts
    • FAQ/Code Snippet Repository
  • SQL / Database
    • MySQL Help
    • PostgreSQL
    • Microsoft SQL - MSSQL
    • Other RDBMS and SQL dialects
  • Client Side
    • HTML Help
    • CSS Help
    • Javascript Help
    • Other
  • Applications and Frameworks
    • Applications
    • Frameworks
    • Other Libraries
  • Web Server Administration
    • PHP Installation and Configuration
    • Linux
    • Apache HTTP Server
    • Microsoft IIS
    • Other Web Server Software
  • Other
    • Application Design
    • Other Programming Languages
    • Editor Help (Dreamweaver, Zend, etc)
    • Website Critique
    • Beta Test Your Stuff!
  • Freelance, Contracts, Employment, etc.
    • Services Offered
    • Job Offerings
  • General Discussion
    • PHPFreaks.com Website Feedback
    • Miscellaneous

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Location


Interests


Age


Donation Link

Found 28 results

  1. b4druz4lsyihab

    How to explode word using php

    how to take a word in php or explode based on luas Bangunan :xxx For example I have string $string =" Kondisi Properti : Bagus Dilengkapi Perabotan : Unfurnished Sertifikat : Lainnya Daya Listrik : 2200 Watt Kamar Tidur : 3/1 Kamar Mandi : 2/1 Luas Bangunan : 92 m² Luas Tanah : 126 m² Jumlah Lantai : - Kondisi Properti : Bagus Sekali Dilengkapi Perabotan : Unfurnished Sertifikat : SHM - Sertifikat Hak Milik Daya Listrik : 6600 Watt Saluran Telepon : 1 Garasi : 3 Kamar Tidur : 4/1 Kamar Mandi : 3/1 Luas Bangunan : 300 m² Luas Tanah : 228 m² Jumlah Lantai : 2.5 "; eg I want to take every "Luas bangunan: xxx" Thanks
  2. shaddf

    rewrite regex

    i have this link Stottoma-BC-textiles/first-bale/-t6/-c2/ and this regex RewriteRule ^.*-([a-z]+)/-t([0-9]+)/-c([0-9]+)/?$ /index.php?Page=$1&baleId=$2&CategoryId=$3 [L] where am going wrong with the regex iam getting not found error
  3. Regex always kills me. I want a string to be only letters, numbers, dash, underscore, or space. if ( !preg_match( $pattern, $str ) ){ $err = 'Only letters, numbers, space, underscore and dash are allowed.'; return $err } In this example, what is $pattern ? My best guess was... $pattern = '/[^a-zA-Z0-9_-\s]+/'; ... but it's not working.
  4. ajoo

    an exact string match only

    Hi all, I want to know if it's possible that the regex matches for the exact subject string, instead of checking for the match anywhere inside of a string. to take an example, if the regex is /([A-z0-9])\w+\.\w{3,4}/ and the subject string is , (i.e. the one within the double quotes.) "'sjvjhvbj.bnm'lsjksnkboubouboubsoubsobob.txt" then because the string begin's with a single quote, it should return a mismatch. That is what I would like to achieve. What is happening is that it finds a pattern match inside the string as : sjvjhvbj.bnm which is not what is desired. Thanks all !
  5. I have a file in the same location as my PHP file, say test.txt, and in multiple locations it has content like: - href="http://www.domain.com/entry.php/256/1/this-is-the-title" or href="http://www.domain.com/entry.php/123/2/another-title" which I need replaced within the file to: - href="{EntryNumber=256.link}" and href="{EntryNumber=123.link}" Only the first number is needed for the replacement, it will be between 1 and 999. Everything between the 5th / and the 2nd " can be safely ignored and removed. This is not the only content in the line, and sometimes there may be more than one occurrence per line. I've got this so far: - $buffer = ""; $fp = file($file); foreach($fp as $line){ $buffer .= preg_replace(***struggling with this bit***); } fclose($fp); echo $buffer; file_put_contents($file, $buffer); Am I along the right lines generally? And I have no idea what the preg_replace should be as my regex is a bit trial and error, more error in this case... As always, any help greatly appreciated! EDIT: If it matters, the largest file I need to edit is 39Kb, and includes 175 occurrences of the replacements.
  6. When I read HTML source of below link http://www.dresslink.com/women-candy-color-handbag-leather-cross-body-shoulder-bag-bucket-bag-p-10908.html I can find below data about the product: <script type="text/javascript"> item.stock['ss42356']=[]; DL.item.stock['ss42356']['qty']=56; DL.item.stock['ss42356']['sku']='SV000837_B'; DL.item.stock['ss42356']['inexistence']=0; DL.item.stock['ss42356']['down_shelf']=0; DL.item.stock['ss42356']['procurement_cycle']='8'; DL.item.stock['ss42356']['paid_set']=[]; DL.item.stock['ss42356']['paid_set'].push(35630); DL.item.color_image['35630']='of7ea7'; DL.item.stock['ss42357']=[]; DL.item.stock['ss42357']['qty']=29; DL.item.stock['ss42357']['sku']='SV000837_G'; DL.item.stock['ss42357']['inexistence']=0; DL.item.stock['ss42357']['down_shelf']=0; DL.item.stock['ss42357']['procurement_cycle']='6'; DL.item.stock['ss42357']['paid_set']=[]; DL.item.stock['ss42357']['paid_set'].push(35631); DL.item.color_image['35631']='of710e'; DL.item.stock['ss42358']=[]; DL.item.stock['ss42358']['qty']=14; DL.item.stock['ss42358']['sku']='SV000837_BR'; DL.item.stock['ss42358']['inexistence']=0; DL.item.stock['ss42358']['down_shelf']=0; DL.item.stock['ss42358']['procurement_cycle']='17'; DL.item.stock['ss42358']['paid_set']=[]; DL.item.stock['ss42358']['paid_set'].push(35632); DL.item.color_image['35632']='of77c1'; DL.item.stock['ss42359']=[]; DL.item.stock['ss42359']['qty']=36; DL.item.stock['ss42359']['sku']='SV000837_O'; DL.item.stock['ss42359']['inexistence']=0; DL.item.stock['ss42359']['down_shelf']=0; DL.item.stock['ss42359']['procurement_cycle']='7'; DL.item.stock['ss42359']['paid_set']=[]; DL.item.stock['ss42359']['paid_set'].push(35633); DL.item.color_image['35633']='of7136'; </script> I need to know the quantity for each SKU, so I need to produce a simple array containing each SKU name and it's quantity like below $a = array( 'SV000837_B' => '56', 'SV000837_G' => '29', 'SV000837_BR' => '14', 'SV000837_O' => '36', ); Please help me write a PHP code using regex and any other method to provide above array.
  7. First time post, be easy on me... I'm using preg_match_all to return an array with all the matches. I know I'm missing something fundamental, but I either keep looking past it or am more screwy than I know. Sample String CC-BY-ND-NC I'm using the following code preg_match_all("/cc|creative commons|copyright|by|sa|nc|nd/i",$exifmeta['copyright'],$cmeta) I would expect to see Array ( [0] => Array ( [0] => CC [1] => BY [2] => ND [3] => NC ) ) What I get is Array ( [0] => Array ( [0] => CC [1] => BY [2] => ND [3] => NC [4] => sa ) )
  8. spencer9772

    PHP regex

    Could anybody please give me a regex for numbers and dashes only? Thanks
  9. This is my preg_match code: preg_match("/(\d+)|(T)|(A)/", $link, $matches, PREG_OFFSET_CAPTURE, ($off-30) It works and matches the number I want, except it only returns the first character in the $matches array. For instance, if the number it finds is 10, it only returns 1. Now I understand that is what preg_match does, but how would I make that regex ungreedy? I tried adding a *, but it just made an error, and preg match all would keep searching for strings after the first one. All I want is for the first number, regardless of the length of it, to be returned in full. Thanks for any help.
  10. Hey all, maybe someone can help me with this problem: I am using PHP and i want to extract the red text including the orange text but only between the blue text. i tried a lot, but i cant find the solution. This is what i tried: $repattern = '/<td class="program_date">(\s+\S+.+)\s+.+(\s\S.+)<\/a>/i'; The final result should look like this: Array with following Data inside: Mo, 09.06.2014 13:45 16:15 Di, 10.06.2014 13:45 Mi, 11.06.2014 13:45 16:15 and so on.. Thanks in advance. Here is a part from source: <td class="program_time"> <span class="program_head">Vorstellungen:</span><br /> <table> <tr> <td class="program_date"> Mo, 09.06.2014 </td> <td><a href='http://fmzimst.kinokartenreservierung.at/reservierung.php?id=74380' target="_top">13:45</a> </td> <td><a href='http://fmzimst.kinokartenreservierung.at/reservierung.php?id=74381' target="_top">16:15</a> </td> </tr> <tr> <td class="program_date"> Di, 10.06.2014 </td> <td><a href='http://fmzimst.kinokartenreservierung.at/reservierung.php?id=74384' target="_top">13:45</a> </td> </tr> <tr> <td class="program_date"> Mi, 11.06.2014 </td> <td><a href='http://fmzimst.kinokartenreservierung.at/reservierung.php?id=74388' target="_top">13:45</a> </td> <td><a href='http://fmzimst.kinokartenreservierung.at/reservierung.php?id=74389' target="_top">16:15</a> </td> </tr> <tr> <td class="program_date"> Do, 12.06.2014 </td> <td><a href='http://fmzimst.kinokartenreservierung.at/reservierung.php?id=74392' target="_top">13:45</a> </td> <td><a href='http://fmzimst.kinokartenreservierung.at/reservierung.php?id=74393' target="_top">16:15</a> </td> </tr> </table> </td>
  11. Hi, I was wondering if some kind person could help me with this. I need to make a call to file under linux that returns various SMART HDD data. From that file I want to see that each line ends in OK. I also want to extract the HDD Temperature from a line with a specific identifier on it. Filename = get_hd_smartinfo -d1 Response = 001 Raw_Read_Error_Rate 0 100 100 016 OK 002 Throughput_Performance 0 100 100 054 OK 003 Spin_Up_Time 321 (Average 164) 237 237 024 OK 004 Start_Stop_Count 6286 099 099 000 OK 005 Reallocated_Sector_Ct 0 100 100 005 OK 007 Seek_Error_Rate 0 100 100 067 OK 008 Seek_Time_Performance 0 100 100 020 OK 009 Power_On_Hours 30115 096 096 000 OK 010 Spin_Retry_Count 0 100 100 060 OK 012 Power_Cycle_Count 81 100 100 000 OK 192 Power-Off_Retract_Count 7535 094 094 000 OK 193 Load_Cycle_Count 7535 094 094 000 OK 194 Temperature_Celsius 42 142 142 000 OK 196 Reallocated_Event_Count 0 100 100 000 OK 197 Current_Pending_Sector 0 100 100 000 OK 198 Offline_Uncorrectable 0 100 100 000 OK 199 UDMA_CRC_Error_Count 0 200 200 000 OK Line = 194 Temperature_Celsius Value I want to capture = 42 in this case. I am sure there is an easier way than my tired old brain suggests, which is to output to a file, read file, grab line then somehow grab value, in a huge block of code. Thanks to anyone who can help me out. Kind regards, jB
  12. I thought this should be a very trivial issue but I was wrong. I have a name filteration function below that checks user input for: empty string, regex pattern, length of string In using the function ro check user input, I am using the elseif logic function as shown below. I think the 'elseif conditional expression evaluates to TRUE' ( returning my custom error code 100) , when it should not, or am I missing something?? function CheckFullname($string, $maxlen, $minlen) { /* define error codes 100 = wrong pattern match 101 = string is too long 102 = string is too short 0 = empty input */ // now we see if there is anything in the string if ($string = '') { return 0; } // then we check fullname format elseif (!preg_match('/^(?:[\p{L}\p{Mn}\p{Pd}\'\x{2019}]+\s[\p{L}\p{Mn}\p{Pd}\'\x{2019}]+\s?)+$/u', $string)) { return 100; } //how long the string is elseif (strlen($string) > $maxlen) { return 101; } // how short the string is elseif (strlen($string) < $minlen) { return 102; } else { // if all is not well, we return true return true; } } // this function executed below is returning error code 100. $string = "John Doe"; if(Checkfullname($string, 40, 4)== 0) { echo 'Your name is required.'; } elseif(Checkfullname($string, 40, 4) == 100) { echo 'Please provide your full name without any funny characters.'; } elseif(Checkfullname($string, 40, 4)== 101) { echo 'Your name should be at most 40 characters long.'; } elseif(Checkfullname($string, 40, 4)== 102) { echo 'Your name should be at least 4 characters long.'; } else { $fullname = safe($string); }
  13. I am building a bbcode system to integrate the prism synthax highlighter into my custom php bulletin board; there are some issues with my regex synthax. This is what i need to achieve: Allow users to post text alone, or code and text but never code alone. Code may be preceded by text or text may be included after the code. bbcode // Function to convert BBcode in HTML tags function formatBBcode($str) { $str = preg_replace('/\[code](.+?)\[\/code]/si', '<section class="language-php"><pre><code>$1</code></pre></section>', $str); return $str; } validation code: $var = '[code]<!DOCTYPE html>[/code] Some text'; // post text alone or nothing at all if(!preg_match('~[[:alnum:]]~', trim(preg_replace('~\[code\].*?\[/code\]~', "", $var)))) { echo 'Please add some text...'; } else { // empty code tags if(preg_match('~\[code\]\s*\[/code\]~', $var)) { echo 'The code tags can not be empty!'; // If there are no issues } else { echo "Everything is ok!"; } } With the present code, this is my observation when code alone is posted: If the code is on a single line the 'Please add some text' warning is thrown up. e.g //This throws up warning 'please add some text' [code]some code[/code] However if the code is on multiple lines, then it gets posted without any warning. e.g //This does not throw up any warning but gets posted [code]some code [/code] I need help in resolving this. Thanks.
  14. I suck at Regex. Can someone tell me the PHP regex check to see if a string is 12345-6789 .... meaning, five digits, a dash, and then four digits? I'm sure it's quite simple for a Regex pro. Thank you.
  15. mrwaqasbaig

    How to to regex here

    I have a CSV file which has more than 50k records and i want to convert this using regex Item Code,,Qty CMAC-389109,,6 ,Serial No., ,954zg5, ,ffnaw8, ,gh8731, ,gxj419, ,hc6y9q, ,y65vh8, CMAC-394140,,1 ,Serial No., ,4cu3z7, and I want to convert this data to below format: ItemCode,Serial Number,Qty CMAC-389109,"954zg5, ffnaw8, gh8731, gxj419, hc6y9q, y65vh8",6 CMBM-394140,"4cu3z7",1 Can i achieve this using find and replacement ? Any help will be highly appreciated.
  16. The bbcode below is not parsing code on multiple lines or recognizing line breaks, except the full content code is on one line. <?php function bbcode2html($var) { // code synthax highlighter $var = preg_replace('/\[code](.+?)\[\/code]/i', '<pre><code>$1</code></pre>', $var); return $var; } $content= '[code] <!DOCTYPE html> [/code]'; echo $content= bbcode2html($content); ?> I attempted introducing a new line recognition character into the regex as shown below, but its not working. <?php function bbcode2html($var) { // code synthax highlighter $var = preg_replace('/\[code]\r\n(.+?)\[\/code]/i', '<pre><code>$1</code></pre>', $var); return $var; } $content= '[code] <!DOCTYPE html> [/code]'; echo $content= bbcode2html($content); ?> I would appreciate your suggestions. Thanks.
  17. kwame123

    regex not working

    this is my code $re = '/[^\W][a-zA-Z\d.-]{3,20}/'; if(!preg_match_all($re, $username)){ do something }else{ do somthing else } $username is a $_POST['username']; when i submit a 3 letter word it works but when i use symbols like $ and ! and etc it still goes through, im trying to get a regex where the username is 4-20 characters long and only the alphabet and numbers and dots and dash but dots and dashs cant be next to each other thx
  18. Is there a difference between a single quote regex and and double quote regex ? for example : <?php $res1 = preg_match('/shi*t/', $comment); $res2 = preg_match("/shi*t/", $comment); ?> Thank you
  19. subhomoy

    need help in regex

    hello every body, Currently i'm scraping web data for a demo project but i cant preg_match the value from this html. The html code is <div class="carouselContainer leftDisabled"> <ul class="carousel leftDisabled"> <li> <div class="thumbContainer"> <div class="thumb" style="background-image:url(http://img6a.flixcart.com/image/mobile/v/h/g/samsung-galaxy-core-2-sm-g355h-100x100-imadzb4ywyj25mw4.jpeg)" data-imageId="IMADZB4YWYJ25MW4"> </div> </div> </li> <li> <div class="thumbContainer"> <div class="thumb" style="background-image:url(http://img6a.flixcart.com/image/mobile/v/h/g/samsung-galaxy-core-2-sm-g355h-100x100-imadzb4zhk4855ny.jpeg)" data-imageId="IMADZB4ZHK4855NY"> </div> </div> </li> <li> <div class="thumbContainer"> <div class="thumb" style="background-image:url(http://img6a.flixcart.com/image/mobile/v/h/g/samsung-galaxy-core-2-sm-g355h-100x100-imadzwrpmdwhnxg7.jpeg)" data-imageId="IMADZWRPMDWHNXG7"> </div> </div> </li> <li> <div class="thumbContainer"> <div class="thumb" style="background-image:url(http://img6a.flixcart.com/image/mobile/v/h/g/samsung-galaxy-core-2-sm-g355h-100x100-imadzwvvz3deeh4c.jpeg)" data-imageId="IMADZWVVZ3DEEH4C"> </div> </div> </li> </ul> </div> The regex i've used is preg_match_all('|<div class="carouselContainer leftDisabled"+>(.*)</div+>|U',$txt,$matches3); I want only the images images url from that specific block. Can anybody help me in this plz...
  20. jolapin

    i need a regular expression

    Hi people, i need to find 16x150gr in Dried Pomegranate Arils16x150gr but the format can vary from Mt Ceder Balsamic Vinegar 12x250ml to Mt Ceder Balsamic Vinegar 2x2ltr to Dried Kalamata Olives 4x1kg. i guess you got the drift i tried something like : '/[1-9]+x[1-9]+[a-z]+/' but i am so useless at regex. Thank you!
  21. johnrdorazio

    lookahead not so greedy

    I need to match n occurrences of "." in a string following specific rules. The number of occurrences found by the regex should correspond with the exact amount of "."'s in the string. The rules are: 1) every "." must be preceded by at least one digit from 1-9, and can be preceded by up to two other digits from 0-9 (basically, values from 1-999) 2) every "." must be followed by at least one digit from 1-9, and can be followed by up to two other digits from 0-9 (again, values from 1-999). Sample valid strings are: 1) "1.3.5.7.9" 2) "21.23.25.27.29" Sample invalid strings are: 1)"01.5.7.9" (first digit of the number preceding the dot cannot be a zero) 2) "1.05.7.9" (first digit of the number preceding or following the dot cannot be a zero) 3) "1.5.7777.9999" (cannot have more than 1 digit with value 1-9 and up to two more digits with value 0-9 (so up to 3 digit numbers); here we have four digit numbers) I'm using preg_match_all to match all occurrences of the dot in the string, and I'm using lookaheads seeing that the digits matched are shared between the dots (the same digit that is preceding a dot is following another dot). The problem is, when I have two or three digit numbers, I'm getting more matches than I need. Here is my pattern: /(?=([1-9][0-9]{0,2}\.[1-9][0-9]{0,2}))/ Here is my test subject: "Mt1,1-15.17.19" There are only two dots, but I am getting four matches: array ( 0 => array ( 0 => '', 1 => '', 2 => '', 3 => '', ), 1 => array ( 0 => '15.17', 1 => '5.17', 2 => '17.19', 3 => '7.19', ), ) I would like to get only two matches ('15.17' and '17.19'), as many matches as there are dots that fall within the rules but no more. <?php $string = "Mt1,15.17.19"; if(preg_match_all("/(?=([1-9][0-9]{0,2}\.[1-9][0-9]{0,2}))/",$string ) != substr_count($string ,".") ){ echo "There are ".substr_count($string ,".")." dots in this string, but there are ".preg_match_all("/(?=([1-9][0-9]{0,2}\.[1-9][0-9]{0,2}))/",$string )." valid occurrences of the dot!"; } ?> Since there can't logically be more valid occurrences than actual occurrences, for the time being I'm just using a "less than" operator instead of a "not equals" operator. But I would like to learn how to get a regex pattern that matches the exact amount of valid instances.
  22. Hi, I'm trying to retrieve the integer value between the <span> tag from a HTML source code. HTML source code: <span> (3861822) </span> This is the php code: <!DOCTYPE html> <html> <body> <?php //use curl to get html content function getHTML($url,$timeout) { $ch = curl_init($url); // initialize curl with given url curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER["HTTP_USER_AGENT"]); // set useragent curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // write the response to a variable curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); // follow redirects if any curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); // max. seconds to execute curl_setopt($ch, CURLOPT_FAILONERROR, 1); // stop when it encounters an error return @curl_exec($ch); } $html=getHTML("http://www.alibaba.com/Products",10); preg_match("/<span>(.*)<\/span>/i", $html, $match); $title = $match[1]; echo $title; ?> </body> </html> Whenever I try to run it, this error will come out: Notice: Undefined offset: 1 in C:\xampp\htdocs\myPHP\index.php on line 19. How to correct it so that it will display all the integer value within the tag name but without the bracket? Thanks
  23. Til22

    conditional regex matching

    I am trying to identify the username from a series of windows logs. I have been using (?:User Name:|Account Name:)\s*([\S]+) and it works for examples 1-4, however I'm having problems with example 5. Because it has two occurrences of the pattern Account Name: in the string I can only get the regex to return the first match, i.e. USER-PC$. How can I tell regex, that if there are two Account Name: patterns in the string, or the string contains the pattern "New Logon:" then return the second Account Name: match, i.e. John.Doe? eg 1 - The screen saver was invoked. Subject: Security ID: S-X-X Account Name: John.Doe Account Domain: INTERNAL Logon ID: 0xa4091 Session ID: 1 eg 2 - User initiated logoff: Subject: Security ID: S-X-X Account Name: John.Doe Account Domain: INTERNAL Logon ID: 0x3d95c This event is generated when a logoff is initiated. No further user-initiated activity can occur. This event can be interpreted as a logoff event. eg 3 - User Logoff: User Name: John.Doe Domain: INTERNAL Logon ID: (0x0,0x458E4AB4) Logon Type: 8 eg 4 - Successful Network Logon: User Name: John.Doe Domain: INTERNAL Logon ID: (0x0,0x43) Logon Type: 8 Logon Process: Advapi Authentication Package: Negotiate Workstation Name: USER-PC Logon GUID: {2e483a4f-} Caller User Name: USER-PC $ Caller Domain: INTERNAL Caller Logon ID: (0x0,0x7) Caller Process ID: 4816 Transited Services: - Source Network Address: xx.xxx.xx.x Source Port: 35029 eg 5 - An account was successfully logged on. Subject: Security ID: S-X-X Account Name: USER-PC$ Account Domain: INTERNAL Logon ID: 0x3e7 Logon Type: 2 New Logon: Security ID: S-X-X Account Name: John.Doe Account Domain: INTERNAL Logon ID: 0xa4062 Logon GUID: {23-xx-22} Process Information: Process ID: 0x2fc Process Name: C:\Windows\System32\winlogon.exe Network Information: Workstation Name: USER-PC Source Network Address: xx.x.x.x Source Port: 0 Any help would be appreciated:)
  24. I have a PHP comments filtration/validation script incorporated into my PHP/mysql custom built blog (under development). This script uses REGEX to evaluate the format of user created comments. This function is supposed to accomplish the following tasks: All code except those in the whitelist must be wrapped in the permitted bbcode tags. The bbcode tags can not be empty The bbcode tags must be used in pairs other forms of bbcode tag must be rejected except if wrapped in the permitted bbcode tag user can not post only code, some descriptive text must be added to explain code. this text can be before or after the code. posted comment string must satisfy minimum and maximum length criteria I shall provide the developer with my current PHP script so he may understand how to lay the script out. If your are good at REGEX, contact me. Thanks.
  25. I have a regex expression that validates a set of mobile numbers: The numbers have optional prefixes (+234 or 234 or 0) and I have used the alternation with the pipe character. Immediately following the international code or zero character is a set of service provider specific identifiers that I have also specified the options using the alternation character. Based on the regex I have, this number should not be valid (12349098766543); but the regex returns it as valid. It appears the there is a match on 909 in the code. But shouldn't the presence of 1 at the beginning of the test string enforce a validation failure? What is wrong with the regex i have here? function check_number($number) { if(!preg_match('/[+234|234|0]?(704|702|803|806|703|706|813|816|810|814|903|802|708|808|812|701|902|809|817|818|909|908|805|705|815|807|811|905)\d{7}$/', $number)) { return 'Invalid Phone Number'; }else{ return 'valid Phone Number';} The execution below should fail, but is is passed as valid. $str = '12349098766543'; echo check_number($str);
×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.