Design
<div>
<asp:TextBox ID="txtMob" TextMode="MultiLine"
onchange="if (this.value.length > 21) {this.value=this.value.substring(0,1); return false; }"
onkeypress="if (this.value.length > 21) {this.value=this.value.substring(0,21); return false; }"
runat="server">
</asp:TextBox>
<ajaxToolkit:FilteredTextBoxExtender ID="flterMobile" runat="server"
TargetControlID="txtMob" FilterType="Custom" ValidChars="1234567890,"
></ajaxToolkit:FilteredTextBoxExtender>
<asp:Button ID="btnSubmit"
runat="server" Text="Submit" onclick="btnSubmit_Click" />
</div>
Code:
using System.Text;
protected void btnSubmit_Click(object sender, EventArgs e)
{
StringBuilder strListMobileNumber = new StringBuilder();
string strvalidString = string.Empty;
string strInvalidString = string.Empty;
string inputstr = txtMob.Text.Trim();
int strLen = inputstr.Length;
if (inputstr.Contains(","))
{
string[] arr = inputstr.Split(',');
foreach (string str in arr)
{
strLen = str.Length;
if (strLen > 10)
{
strInvalidString += " " + str;
}
else
{
if (strLen == 10 && (str.StartsWith("7") || str.StartsWith("8") || str.StartsWith("9")))
{
if (strListMobileNumber.ToString().Trim() == string.Empty)
{
strListMobileNumber.Append("91" + str);
}
else {
strListMobileNumber.Append("," + "91" + str);
}
}
else { strInvalidString += " " + str; }
}
}
}
else
{
if (strLen > 10)
{
strInvalidString = inputstr;
}
else
{
if (strLen == 10 && (inputstr.StartsWith("7") || inputstr.StartsWith("8") || inputstr.StartsWith("9")))
strListMobileNumber.Append("91" + inputstr);
else { strInvalidString = inputstr; }
}
}
if (strInvalidString != string.Empty)
{ return;
}
string data = strListMobileNumber.ToString();
//sendsms
}
No comments:
Post a Comment