Validating integer value


  I am trying to validate for integer value for phone number and this is my code

<asp:TextBox ID="PhoneNumber" runat="server" MaxLength="11" ValidationGroup="CreateUserWizard1"></asp:TextBox>

<asp:CompareValidator ID="CompareValidator3" runat="server" ControlToValidate="PhoneNumber"

Display="Dynamic" ErrorMessage="Please Enter Numeric value" Operator="DataTypeCheck"

Type="Integer" ValidationGroup="CreateUserWizard1"></asp:CompareValidator>


but if the length of entered number is greater than 9 it will not save and if its 9 or less it works fine

How can I solve this problem?


1/17/2008 1:17:15 AM 93655 articles. 3 followers. Follow

5 Replies

Similar Articles

[PageSpeed] 52

search on the web for regular expression validation of numbers in combination with asp validators, this will solve your problem

regards, roni
speed up your applications with distributed caching or replicated caching: - its free!
1/17/2008 1:34:51 AM

What should be the expression to validate for numbers??


This is what I tried

<asp:TextBox ID="PhoneNumber" runat="server" MaxLength="50" ValidationGroup="CreateUserWizard1" ></asp:TextBox>

<asp:RegularExpressionValidator id="RegularExpressionValidator1" runat="server"






Phone must be 10-11 numeric digits


1/17/2008 1:56:09 AM

Hi Sammus,

You can use javascript like below

<script type ="text/javascript" language="javascript" >
function ValidateText(i)
    i.value = i.value.replace(/[^\d]+/g, '');

In your textbox add the onkey up..

 <asp:TextBox ID="TextBox1" runat="server" OnTextChanged="TextBox1_TextChanged" onkeyup = "ValidateText(this)"></asp:TextBox> 



"Code, Beer and Music" that's my way of being a programmer!

How to get your Forum Question Answered | Blog | CodeASP.NET
1/17/2008 2:50:18 AM

Hi sammus,

        Based on my understanding, you wana validate if the PhoneNumber.Text is a value of a valid phone number. There is a Regular Expression Validator in the Visual Web Developer. You can simplely add it onto your page. Just don't forget to set the "CtrolToValidate" property and select ValidateExpression in the property window. It has some formats of phone numbers of various countrys already.

        If all the formats don't fit your demand, please describe explicitly what is the format of the phone number that you want.

        For example, is you want it to be like this: 010-87358217 or simplely 87358217, then you should set the ValidateExpression like this: (\d{3}-)?(\d{8}). This will match all the xxx-xxxxxxxx or xxxxxxxx like input digital numbers.

        As well, don't forget to add a RequiredFieldValidator to the TextBox if needed.

        Moreover, You can always find regular expression very easily at this site.



1/18/2008 7:16:55 AM

Hi Sammus,

try this 


where {10} will be the parameter to limit the phone number digits. u can modify it as per ur req.

it will compulsory take 10 numbers neither less nor more than that ok. 

Hope this helps.




1/18/2008 7:34:31 AM

Similar Artilces:

Passing Values from a Web Form to Another Web Form
Hello All! I am trying to pass values from one web form to another web form. I know that there are 3 ways of doing this: queryString, Server.Transfer and Session. I am using the Server.Transfer method. But I am not able to create, in my 2nd web form, an instance of my 1st web form. My 1st Web form is named CallTrack.aspx and my 2nd is named Export.aspx. What I mean is something like this: Public value as CallTrack. I can't create it in my 2nd web form because when the intellisense is displayed, there's no CallTrack in the options. Thanks!   How about using cross-...

Implementing .Net Form into an web form, can this be done
I am new here, but have been searching for a while, and may not have the correct lingo to find what I am looking for.  I am tasked with implementing a .exe application that was writen vb6 then converted to .net into a new website my team is developing. The idea is to put each of the 3 different forms in this .exe application of 3 different .aspx pages. I have attempted multiple things to get this into the page and even started to just rewrite it as an web form, but even then I can't reuse any of the code since the System.Web.UI.Page doesn't inherit the sa...

passing values to .net web form application
Hi Can any explain me abt how to pass values to my .NET web form application (designed using PB 11.1) from other web application? My intension is to redirect from a web application (ASP.NET to .net web form application) to my web application with user information. Thanks & Regards, Anbazhagan From the "Deploying Applications and Components to .NET" manual: >>> Starting an application with command line parameters If your application requires command line parameters, you can assign values to the PBCommandParm global property before you deploy the...

Send e-mail with web form values (
I'm sure this is very simple but;I have a form with numerous (<50) textbox controls and related Label controls; ie: <asp:Label ID="Label1" runat="server" Text="Last Name: "></asp:Label> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>When the form is submitted I want to loop through each label control and textbox control and get their Text values for the e-mail without specifying each control. Anyone have suggestions on the best way to do this?Any assistance appreciated greatly!   Here is a solution for you in

windows forms in vb .net into web forms
we are creating a database driven website as part of our project. currently we have forms connecting to the database created in visual basic. these windows forms we need to convert into web forms which are asp .net compatible. can u give me an answer or show me a way. Hi, because of the difference in nature between web and win applications you'll need to reimplement at least the UI part. If you have a multitiered application in which the busines logic and data access are in different parts/assemblies you can reuse them. Grz, Kris.Read my blog. Handy Firefox plugins for web developers.Wor...

getting values from a web form to windows form
Hot Requirement ..... Is there any possible of getting values from a web form to windows form ????? Yes One way i to use the WebRequest and WebResponse classes of the System.Net namespace. For example:  WebRequest request = WebRequest.Create("URL of the web page); WebResponse response = request.GetResponse(); StreamReader reader = new StreamReader(response.GetResponseStream()); string content = reader.ReadLine(); ....    Reza Nassabehwww.professionalcsharp.comDon't forget to click "Mark as Answer" on the post that helped you. That way fut...

Clearing Web Controls Values from a Web Form
I have a web form and after a user submit it I want to clear the form so that they may submit another entry. I have seen examples in VB of how to loop thru a web form and clear the controls, but I need a C# solution. I have tried the following code, while it does not give me an error, it does not clear the controls on the form. Any suggestions? Thanks! foreach (Control parent in Page.Controls)         {             foreach (Control child in parent.Controls)           ...

.Net Web Form & Web Service Deployment
Hi all I have written some test web services and some web form applications and deployed them to my IIS. That's fine but I now want to deploy them to my real IIS server. I have created an msi for each but the problem is I seem to only be able to deploy to the default web site. Our default web site is turned off and instead we use several other sites. Does anybody happen to if Powerbuilder 11 supports non default web sites? If not do I need to hack the msi and if so can anybody suggest a suitable tool. I have Orca but it's not very friendly. Unless of course I knew exactly w...

validate Textbox in Web User Control from web form?
ASP.NET 2.0 I have a web user control that contains a textbox.  I need to add some validation (like requiredfieldvalidator, comparevalidator, etc). I would normally add the validator to my web user control by placing the validator next to my textbox.  However, I need the validation message somewhere else on my web form, not near the user control. So how would I associate a validation control on my web form with the text box inside my web user control?  Can this be done; any alternatives out there? Thanks!   The error message should occur wherever you place the vali...

How to Make Web Forms from other Web Forms
In putting together an ASP.NET application for a biz application, we have come to the point where there are three different types of basic forms which have, for the most part, been perfected. Now its is a matter of cloning those forms for various uses and modifying or adding code to suit the particular need. Copy and paste works OK, but there is a lot of changing of certain words, etc. Is there a way in ASP.NET to take these basic forms, turn them into classes or templates, create forms from them, then add or overwrite code? ? (Anybody who is a Vis Fox Pro programmer would know imme...

Web forms and mobile web forms
Hey everyone, I am looking to develope a web site that depending on the device connecting to it, it will display a certain page. In this case im looking to create a web and wap version of the same project. I have the Web forms version finished using ASP.NET and C# and I am wondering how to create the mobile web form and incorporate it in the project. In the project folder, can I just add a mobile web??? But what about displaying device specific pages?? Cheers -Dudach Yes, you can add mobile web forms and controls to your Web Application project. No problem. For device/br...

How to validate for integer input in a texbox of the form control when column is integer
I have a sql table with a column that is set to int. In my aspx form I set the value of the ValueToCompare property of CompareValidator in the folowing fashion: On a submit, Integer value is not written to sql table. If I remove the validator, everything works fine. <asp:CompareValidator ID="CompareValidator2" runat="server" ControlToValidate="GBDataMovedTextBox" ErrorMessage="Enter a number" Operator="DataTypeCheck" Text='<%# Bind("GBdatamoved", "{0}") %>' Type="Integer"></asp:CompareV...

Retreiving a value from a web form within a web user control
Hi  I have a page (web form) that retreives some data from a database. To be more specific: at some point when user clicks a button (in the web form) there is some ID number retreived from a database in code behind. At the same time the Visible property of the nestet web user control is chamged to true. I want than forward the ID to the web user control so that a grid view can load data from a database for that ID. How can I access that data (the ID) within a web user control context nested in that page?  Kind regards   Check this ;ink

Web form and a gridview on the same page with data validators
I have a form where a user can submit a new customer and directly below that is a gridview where they can view the customer they just submited plus their other customers they have submited in the past. Now this gridview has the edit/update property so the user can modify their customer information. The whole idea is to have 1 single page where a user can do everything they need to without having to be linked to another page. On this page we can submit new customer info and view the status/info of existing customers and edit that info as needed. So far that works fine. I can submit the new c...

For interrupting.web form Resized by position of the div : if div can't dispaly all (such as only top part , then web form heithten the heght),resize the web form
Web Form Resized by position of the div : if div can't dispaly all (such as only top part , then web form heithten the heght),resize the web form ! Because of my pool English, if you can't see , I will explain more ! ThanksGambler is the real life I guess you mean when form grows it also grow parent div element. This is normal. If you want div to stay fixed size and rather clip the form and maybe show a scrollbar, look at overflow property in CSS.Thanks------------------------------------------------------------This posting is provided "AS IS" with no warranties, and confers no ...

Web resources about - Validating integer value -

Talking to police about Ghomeshi allegations was validating: Decoutere
One of the women accusing former CBC host Jian Ghomeshi of violent behaviour is encouraging other potential victims not to be afraid of speaking ...

Validating Input and Interprocess Communication
Describes techniques to use and factors to consider to make your code more secure from attack.

Validating team-by-team R and RBI predictions for 2012 AL Edition
Unless you're a big fan of my writing, you may not know that at this time last year, I wrote for a different SB Nation site: the dearly departed ...

"It is important not to create a precedent validating the prohibition of the sale of any object of a ...
"... regardless of the culture concerned... Our goal has always been to showcase Hopi culture and make it accessible to the largest number of ...

Validating the Donald
Validating the Donald by digby In Salon today , I wrote about the right wing media's immigration backlash strategy by validating Donald Trump's ...

Validating your marketing audience
... enjoyed this, please share it with your network! Want to read more like this from Christopher Penn ? Get daily updates now: The post Validating ...

Validating Albert Einstein, physicists make major discovery about the early universe
In the beginning there was the Big Bang. What we know about this time is that the universe was extremely hot, dense and almost uniform; it was ...

Validating Architecture through LINQ Query
... is simple enough to get validated at a glance. But at a glance is not enough. What about defining custom rules that take care of validating ...

From Data to Action – Best Practices for Validating and Optimizing Your Digital Campaigns - comScore ...
In this webinar, comScore Senior Industry Analyst Jason Patterson explores how you can use comScore's validated data to optimize and improve ...

TDD of a WinForm app – Part 5 – Validating the account data
In our last post, we worked on allowing our user to enter new accounts – basically making our AddAccountForm usable. We were able to do that ...

Resources last updated: 1/5/2016 3:20:00 AM