RegularExpression Validator (Regex) to check whether string has Dot and Hyphen ASP.Net

Last Reply one year ago By Shashikant

Posted one year ago

I have a textbox,I want to validate it to contain alphabets and hypen and dot for Inserting name..

ex for:Dr. HAMID-ULLAL

                                        

@Html.TextBoxFor(m => m.FirstName, new { @class = "form-control validate[required,custom[onlyLetterSQ]]", @id = "firstName" })

 

Posted one year ago Modified on one year ago

Here I have created sample that full-fill your requirement using RegularExpressionValidatior.

HTML

<div>
    Name :
    <asp:TextBox ID="txtName" runat="server" />
    <asp:RegularExpressionValidator runat="server" ControlToValidate="txtName" ValidationExpression="^([a-zA-Z]+)[.]\s?([a-zA-Z]+)[-]([a-zA-Z]+)$"
        ErrorMessage="Invalid Name Format" ForeColor="Red"></asp:RegularExpressionValidator>
</div>

Screenshot

 

I agree, here is the link: http://e-iceblue.com/free-api