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.
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
- Author was Featured
- Bought between 1 and 9 items
- Europe
- Exclusive Author
- Has been a member for 4-5 years
- Interviewed on the Envato Notes blog
- Referred between 200 and 499 users
- Repeatedly Helped protect Envato Marketplaces against copyright violations
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.
<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.
