Created
October 20, 2016 02:59
-
-
Save gilles-leblanc/652928af61ba7372508d78349ddaf484 to your computer and use it in GitHub Desktop.
Telephone Number Model to match database with NUMBER(10) phone field.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class PhoneModel | |
{ | |
public long PhoneNumber { get; set; } | |
private string _phoneString; | |
[DataType(DataType.PhoneNumber)] | |
public string PhoneString | |
{ | |
get | |
{ | |
if (!string.IsNullOrWhiteSpace(_phoneString)) | |
return _phoneString; | |
return DisplayPhoneNumber; | |
} | |
set | |
{ | |
_phoneString = value ?? string.Empty; | |
if (value != null) | |
PhoneNumber = Convert.ToInt64(Regex.Replace(_phoneString, @"[\(\)\-\ ]", string.Empty)); | |
} | |
} | |
public string DisplayPhoneNumber => PhoneNumber > 0 ? string.Format("{0:(###) ###-####}", PhoneNumber) : string.Empty; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment