Wednesday, March 30, 2016

Best regular expression for phone number that accepts many variations

Here is a handy regular expression that will accept many variations of an U.S. phone number, allowing the input to be somewhat flexible.

^\s*[(]?\d{3}[).\-]?\s*\d{3}(\s*|[.\-]?)\d{4}\s*$

// accepted
8015551212
801 555 1212
(801)5551212
801.555.1212
801.555-1212
801-555-1212
(801)555-1212
(801) 555-1212
801-555.1212
(801 555 1212
(801 555 1212
801)5551212

// rejected
8015551212a
80155512122
801a5551212
8015;551212
(801))5551212

Can't RDP? How to enable / disable virtual machine firewall for Azure VM

Oh no!  I accidentally blocked the RDP port on an Azure virtual machine which resulted in not being able to log into the VM anymore.  I did ...