1: using System; 2: using System.Collections.Generic; 3: using System.Text; 4: using System.Text.RegularExpressions; 5: 6: namespace ConsoleApplication1 7: { 8: public class PhonenumberFilter 9: { 10: public bool IsNumberOK(string num) 11: { 12: //this pattern is to match all phone numbers, except a number starting with 15. 13: //the pattern tries to match any of the valid number ranges: 0....-09.... and 10...-14... and 16...->169..... 14: //min length = 5, max length = 11 15: string pattern = "^(0[0-9]{4,10}|1[0-4][0-9]{3,9}|1[6-9][0-9]{3,9}|[2-9][0-9]{4,10})$"; 16: Regex reg = new Regex(pattern, RegexOptions.None); 17: 18: return reg.IsMatch(num); 19: } 20: } 21: } 22:
Comments
Post a Comment