Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Validate Norwegian Mobile Numbers
//Title of this code //Rextester.Program.Main is the entry point for your code. Don't change it. using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; namespace Rextester{ public class Program { public static void Main(string[] args) { var validNumbers = new string[]{"+47 489 95 764", "47 48 99 57 64", "982 70 723", "+47 98 27 07 23"}; var invalidNumbers = new string[]{"+47 689 95 764", "47 78 99 57 64", "382 70 723", "+47 58 27 07 23"}; Console.WriteLine("**** These are valid numbers ****"); foreach(var number in validNumbers){ validateAndLogNumber(number); } Console.WriteLine(); Console.WriteLine("**** These are not valid numbers ****"); foreach(var number in invalidNumbers){ validateAndLogNumber(number); } } public static void validateAndLogNumber(string number){ Console.WriteLine(string.Format("The number: \"{0}\" is {1}a valid mobilephone number!", number, (MobilephoneNumberValidator.Validate(number) ? "" : "not "))); } } public static class MobilephoneNumberValidator { private static readonly Regex _matcher = new Regex(@"(?:(?:^*(?:\+?47[49]))|(?:^[49]))\d{7}$"); private static readonly Regex _replacer = new Regex(@"\s+"); public static bool Validate(string number) { return _matcher.IsMatch(_replacer.Replace(number, "")); } } }
run
|
edit
|
history
|
help
0
Terminus Code Example 1
GP-TIME
Subdomain regex
TestCodec1
binary
Login Silencioso
Reed Solomon Demo
stack using LinkedList in C#
How to Count Occurrences of a Word in a String (LINQ) (C#)
Stacks: Balanced Brackets -final