Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Phone number regex validator
Language:
Ada
Assembly
Bash
C#
C++ (gcc)
C++ (clang)
C++ (vc++)
C (gcc)
C (clang)
C (vc)
Client Side
Clojure
Common Lisp
D
Elixir
Erlang
F#
Fortran
Go
Haskell
Java
Javascript
Kotlin
Lua
MySql
Node.js
Ocaml
Octave
Objective-C
Oracle
Pascal
Perl
Php
PostgreSQL
Prolog
Python
Python 3
R
Rust
Ruby
Scala
Scheme
Sql Server
Swift
Tcl
Visual Basic
Layout:
Vertical
Horizontal
//Title of this code //Rextester.Program.Main is the entry point for your code. Don't change it. //Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5 using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; namespace Rextester { public class Program { public static void Main(string[] args) { //Your code goes here var regex = @"^(?<countryCode>[\+][1-9]{1}[0-9]{0,2}\s)?(?<areaCode>0?[1-9]\d{0,4})(?<number>\s[1-9][\d]{5,12})(?<extension>\sx\d{0,4})?$"; var phones = new [] { "02 5555555 x4545", "054 5575487", "02 5555555", "054 5575487", "+1 212 7777777", "212 7777777", "+44 7777 777-777", "+44 20 44444444", "07777 777777", "020 44444444" }; foreach(var phone in phones) Console.WriteLine(Regex.IsMatch(phone, regex)); } } }
Show compiler warnings
[
+
]
Show input
Compilation time: 0.09 sec, absolute running time: 0.17 sec, cpu time: 0.12 sec, average memory usage: 18 Mb, average nr of threads: 5
edit mode
|
history
|
discussion
True True True True True True False True True True