=>Web API
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations;
[RegularExpression(@"^(91)?\d{10}$", ErrorMessage = "invalid country code or mobile no.")]
public string mobileno { get; set; }
=>C Sharp
=>C Sharp
using System.Text.RegularExpressions;
string regex = @"^(91)?\d{10}$";
string inputString = "919876543210";
Match match = Regex.Match(inputString, regex);
=>Java Script
<script>
function Validate() {
var text = document.getElementById("TextBox1").value;
var pattern = "^(91)?\d{10}$";
var result = text.match(pattern);
if (!result)
alert("invalid country code or mobile no.");
}
</script>
<asp:TextBox ID="TextBox1" runat="server" ClientIDMode="Static"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="return Validate();" />
Note:- Input string only valid when mobile no passed with Indian country code i.e. 91.
This comment has been removed by a blog administrator.
ReplyDelete