.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Forum >> ASP.Net >> Post New QuestionBookmark and Share Subscribe to Forum

validation on phone no

Posted By: shahin     Posted Date: November 03, 2008    Points:2   Category :ASP.Net
what is logic to put validation on phone no. in c#?

Responses
Author: Faizal             
Posted Date: November 04, 2008     Points: 5   

Hi,
You can use regular expression validator control to validate phone no and set it "RegularExpression" property to "Phone No".

eg


<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server"
ControlToValidate="TextBox1" ErrorMessage="RegularExpressionValidator"
ValidationExpression="((\(\d{3}\) ?)|(\d{3}-))?\d{3}-\d{4}"></asp:RegularExpressionValidator>


Author: Akhil Raj       [Moderator]      
Posted Date: November 04, 2008     Points: 5   

hi mate,
use Regular expression as Faizal told..try the following url for different regular expressions...

 http://regexlib.com/ 


Author: Athira Sreejith             
Posted Date: December 31, 2008     Points: 5   

Hi..

Use like this..

<asp:RegularExpressionValidator ID="reg_Phone" runat="server" ControlToValidate="txtPhonenumber"
ErrorMessage="Please enter a default 10 digit contact number (eg:111-111-1111)."
ValidationGroup="RegisterValidation" ValidationExpression="((\(\d{3}\) ?)|(\d{3}-))?\d{3}-\d{4}">*</asp:RegularExpressionValidator>

Author: Syed Shakeer Hussain             
Posted Date: April 11, 2009     Points: 5   

Hi
use below code for cell validation
[\d]{10}
here \d means it will takes only digits like 0,1,2,3,4,5..9
{10}means it allows exactly 10 digits(not less than 10 digits or not more than 10 digits)
eg:9012345678

<asp:RegularExpressionValidator ID="reg_Phone" runat="server" ControlToValidate="txtPhonenumber"
ErrorMessage="Please enter a default 10 digit contact number (eg:111-111-1111)."
ValidationGroup="RegisterValidation"
ValidationExpression="[\d]{10}">

</asp:RegularExpressionValidator>

Author: Syed Shakeer Hussain             
Posted Date: April 11, 2009     Points: 5   

Hi
you can validate a Cellnumber without using Validation Controls

user the below code

Validating a cellnumber textbox in Windows Form usinr C#.

First Add a textbox and button on windows form. Keep name of textbox as textcellno. Double click the button and write below code.


using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
String str=Convert.ToString(textcellno.Text);
if(str .Length ==10)
{
String strcell=String.Empty;
for(int i=0;i<10;i ++)
{
if(Char.IsDigit(str[i])) {
}
else
{

MessageBox.Show("InvalidcellNo"); break;

}

}
MessageBox.Show("you cell Number is valid:" + str);
}
else
{
MessageBox.Show("CellNo Should Contain exactly 10 Digits");
}
}
}
}



Post Reply

You must Sign In To post reply
 
 
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery
JavaScript/VBScriptBiztalkWPFPatten/PracticesWCFOthers
www.DotNetSpark.comUnAnsweredAll

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend