Example:
Here is my code of C#
This is regular expression demo in C# in dotfiddle.
string[] array = {"704000233873", "705000233873", "706000233873", "707000233873", "504000233873", "504000233873", "703000233873", "704000233873"};
string regex = @"^(50|70)(4|5)\d{9}$";
foreach (var item in array)
{
Console.WriteLine(Regex.IsMatch(item, regex));
}
and Results are below:
True
True
False
False
True
True
False
True
When I try the same RegEx on Javascript JS or Chrome it returns false.
$(function() {
var $checker = $('#checker');
$checker.click(function(ev) {
var inputFieldVal = $.trim($('#in').val());
console.log(inputFieldVal); // Alg
var regExpPattern = '^(50|70)(4|5)\d{9}$',
re = new RegExp(regExpPattern);
console.log(re); // /^Al/gim
// Get text out of div#x
var text = $('#x').text();
// Trim and 'convert' to an array...
text = $.trim(text).split('\n');
console.log(text); // ["Aldor", "Aleph", "Algae", "Algo", "Algol", "Alma-0", "Alphard", "Altran"]
for (var index = 0, upper = text.length; index < upper; ++index) {
console.log(
re.test(text[index].trim()), text[index]);
}
});
})
<form>
<input id="in" />
</form>
<div id="x">
704000233873
705000233873
706000233873
707000233873
504000233873
504000233873
703000233873
704000233873
</div><button id="checker">check!</button>
And the results are below.
["704000233873", "705000233873", "706000233873", "707000233873", "504000233873", "504000233873", "703000233873", "704000233873"]
false, "704000233873"
false, "705000233873"
false, "706000233873"
false, "707000233873"
false, "504000233873"
false, "504000233873"
false, "703000233873"
false, "704000233873"
What am I missing or why they return false?
Any advice?