1590 posts
  • Has been part of the Envato Community for over 3 years
  • Has been a beta tester for an Envato feature
  • Has collected 10+ items on Envato Market
  • Sells items exclusively on Envato Market
webdesignerart says

Friends i want to match first 3 number digit or first 3 string. Example: i type in input field “800 4578 5147” the first 800 i want to check is true or false. second some more digits/string like 800, 888, 877 i want to check when we get value from input field these string/digits matches are found or not.

Need Help.

147 posts
  • Has been part of the Envato Community for over 4 years
  • Has referred 10+ members
  • Has sold $250,000+ on Envato Market
  • Has collected 10+ items on Envato Market
+2 more
FlexiPress says

Do we talk about PHP here? If yes, I don’t know if you need Regex or not for this case… I prefer to use simple strpos PHP function to find the occurence of string…

reference: http://php.net/manual/en/function.strpos.php

204 posts Bold WordPress Theme Development
  • Has been part of the Envato Community for over 6 years
  • Has referred 200+ members
  • Has sold $250,000+ on Envato Market
  • Interviewed on an Envato blog
+6 more
srhnbr says

How about something like:

//Validate numbers like 123-456-7890

function validate_num ( $num) {
   return preg_match( '/^\d{3}-\d{3}-\d{4}$/', $num) );
}

Adjust as needed.

1590 posts
  • Has been part of the Envato Community for over 3 years
  • Has been a beta tester for an Envato feature
  • Has collected 10+ items on Envato Market
  • Sells items exclusively on Envato Market
webdesignerart says
friends thnkx for your help, now a little problem i am facing, first see my code:
<script type="text/javascript"> 
var get_tollandlocal = '(987) 89789-897';
var match_tollandlocal = get_tollandlocal.match(/800|888|877|855|866/gi);

      if(match_tollandlocal != null){

    alert(match_tollandlocal);

    $('body').html($('body').html().replace('(987) 89789-897','<span id=avidtoll><b>987 89789-897</b></span>'));

    }

    if(match_tollandlocal == null){

    alert('not match')

    $('body').html($('body').html().replace('(987) 89789-897','<span id=avidlocal><b>987 89789-897</b></span>'));

    }

  </script>

it work good :) but

if to many string its found body like

1) (987) 89789-897

2) (987) 89789-897

it works like charm

then

3)(987) 89789-897

4)(987) 89789-897

its stop means its not work more then 2 searches. and without brackets see the code:


$('body').html($('body').html().replace(/(987) 89789-897/g,'<span id="avidlocal"><b>987 89789-897</b></span>'));

it works good, the problem is when have string in bracket to search it works for only 2 times not continues searches.

AND SORRRY FOR MY ENGLISH .

Need Help.

by
by
by
by
by
by