lovettjay
asked on
MVC5 Dataformat String for Phone not working
I have tried several different things and have had no luck
In my member class, so I know it's a string.
In the metadata folder
Also in the view I have tried a few different things:
The only time I can get it to work it when I hard code a phone number
In my member class, so I know it's a string.
public string members_phone { get; set; }
In the metadata folder
[Required(ErrorMessage = "Phone is required")]
[Display(Name = "Phone")]
[DisplayFormat(DataFormatString = "{0:(###)###-####}", ApplyFormatInEditMode = true)]
[RegularExpression(@"^[0-9]{0,15}$", ErrorMessage = "Phone Number should contain only numbers - Example: 8008008000")]
[StringLength(15)]
public string members_phone { get; set; }
Also in the view I have tried a few different things:
@String.Format("{0:(###) ###-####}", Model.members_phone)
@String.Format("{0:(###) ###-####}", Html.DisplayFor(model => model.members_phone))
@Convert.ToString(String.Format("{0:(###) ###-####}", Model.members_phone))
The only time I can get it to work it when I hard code a phone number
@String.Format("{0:(###) ###-####}", 8008008000)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you for your help
ASKER