Web Forms :: How To Add Validation So It Doesn't Accept Empty Strings Or Numbers
Jan 6, 2010
i am using a search box for my application which returns a dataset. however when i click on the search button it returns an empty table result. how could i add validation so it doesnt accept empty strings or numbers.
I'm currently stuck with a problem with MVC2 RC and validation on a dropdownlist :
I have a page with some fields and a dropdownlist. The dropdownlist is not a mandatory field so I would like to save a null value into my property.
Unfortunately, I can't validate my page with a null selected value, because when I look into the modelstate just on the first line of my action, I've already an error telling me I must choose an item.
Is it normal working of dropdownlist validation or is it a bug ?
I want the validation condition to be: on a pair of textboxes, to be valid as long as at least one of them isn't empty.
So I put a customvalidator on the 2nd textbox, hooked up to the following server code and client code:
<script type="text/javascript"> function ECPhoneOrEmailRequired(source, args) { var ecPhone = document.getElementById("txtEmergencyPhone"); var ecEmail = document.getElementById("txtEmergencyEmail"); if (ecPhone.value.length < 1 && ecEmail.value.length < 1) { args.IsValid = false; } else { args.IsValid = true } } </script> Protected Sub CustomValidator1_ServerValidate(ByVal source As Object, ByVal args As System.Web.UI.WebControls.ServerValidateEventArgs) 'args.IsValid If (txtEmergencyPhone.Text = String.Empty And txtEmergencyEmail.Text = String.Empty) Then args.IsValid = False Else args.IsValid = True End If End Sub
From what I can tell thru breakpoints, this code works fine as long as there's something in one of the two textboxes. When both textboxes are empty, the code is never called - and so both boxes empty ends up being allowed.
So what's the correct way to validate one-or-the-other-nonempty condition?
I had been doing a type check for Double for an input field on a web page but now I need to allow commas. Can this be done using a CompareValidator or do I need to use a regex validator?
I need to validate the text box at server side by using regular exp which should accept 1 or 2 or 3 or 4 or 5 digits numbers .Need to restrict decimal part.
Ex: 1 or 23 or 455 or 5643 or 45667 --Should accept.
1.3, .2, 33.3 , 444.55 ,5555.99 -- should not accept.
I'm trying to write a regular expression that allows positive & negative floating point numbers, but doesn't allow empty strings and characters.I have managed to create this
[Code]....
but it allows empty strings and I can't figure out how to add [+-].
My program is a web app which asks the user to input a temperature.
I have A textbox inside formview, ive add litered textbox from ajax and allow only numbers and "."Works fine. THe only problem they can enter multiple dots. I want textbox to accept only following formats: 100, 1234.56 - i.e integers and decimals.
I need to validate integer within a specified range for English and French culture. The integer contains group separator ("," in English culture or " " in French culture). It seems I can't do it with RangeValidator on my machine.
I just want to make sure the RangeValidator can't do this kind validation for Integer before I'm going to write my own control.
I just feel curious because RangeValidator can actually do this kind of validation for Currency!
I have an invoice form where user enters items and amount. I am calculating the amount as the user enters amount in the textfield. I receive an error (Input String was not in correct format) if user enters amount with comma separated values. If there are no commas, my calculation goes through fine.
Using MVC 2 and VS 2010 RC.I have a varchar database column set to NOT NULL and I use the Entity Framework to bind the column to a textbox. I want a user to be able to leave the textbox blank and have an empty string inserted into the database column. However, MVC is trying to set the property to null during the Create postback, which causes ModelState.IsValid to be false and subsequently the validation UI is triggered with the message "The value '' is invalid".Here is the model:
[Code]....
The controller:
[AcceptVerbs(HttpVerbs.Post)] public ActionResult Create(Candidate c ) { if (ModelState.IsValid) // This is false when the textbox is left blank.
In this test application, I am filtering by two ControlParameters. As you can see in the first codeblock, both parameters have a default value of %. This code works great. However, in the second code block, please note that the Default Values are eliminated. The second code block works as long as neither Textbox's text is blank. For some reason, when .NET evaluates the filter expression and inserts "" into the expression, it seems to bug out and case none of my results to be filtered.
I am able to verify this behavior by setting the defaultvalue="" for each ControlParameter.Obviously I have found a workaround, but I would like to know why the FilterExpression breaks down when an empty string is provided.
Code Block 1:
<asp:SqlDataSource ID="Customer_Data" runat="server" ConnectionString='<%$ ConnectionStrings:connectionString %>' SelectCommand="SELECT Station, StoreFront, CustomerID as CustID FROM vStations" [code]...
I have one textbox and I want to allow only integer cannot allow character when I entered character to show the error message , this functionality I want create in server side withou using javascript.
What is the proper way to check for null or empty strings on dynamic objects? This is the only solution I've found so far:
if (admin.PasswordHash.GetType() == typeof(DBNull) || admin.PasswordHash == string.Empty)
If the field is null, the object returned is DBNull.Value, but if the field is empty string, it's return as a System.String object. This makes it impossible to do regular "admin.PasswordHash == DBNull.Value" check, as that will fail whenever the field has been set to empty string. Is my example the right (and only) way to go?
Iīm creating a user page to enable editing their profiles. When hitting the "update" button, it turns out that the field still contains the old value, although youīre looking at the new one, ie the text property of the textbox isnīt the value of the parameter which in fact gets its value from the text property.As far as I know I havenīt done anything I havenīt done before, both in apps and website?
I've a form where I'd like to impede the user from entering any alphabits or special characters. The user can only enter numbers between 0 & 3( both inclusive) no more no less.
How can i achieve this ? I've used RangeValidator. Would this alone be suffice or do we also need to use Expression Validator ?
I'm using MVC 3 RTM, client side validation has been disabled.I have a simple model with one integer field.Server side validation does not accept numbers including one or more thousandseparators.
It shows: "The value '1,000' is not valid for QuantityInStock".It does not matter what culture I use. Both "1.000" and "1,000" are never accepted.
I am working on a website. I am using C# 2008. I want to make a text box that accept only numbers & comma(,). for example-919981424199,78848817711,47171111747 or there may be a single number like 919981424199.
I was able to do one thing My text box only containing number by using this Regular Expression validation.in its property->Validation Expression i wrote "[0-9]+". This is working but now my requirement is to send bulk SMS & each number is separated by (,).