473,386 Members | 1,621 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

TextBox Validation

Hi,

i'm working with c# and MySQL, and i need to validate some textboxes to ensure valid data is inserted to the database.

i did some coding and it works but i need the easiest and the right way to do that and if there is a TOOLBOX for validation that will be great.

Expand|Select|Wrap|Line Numbers
  1. private void textBox1_Validating(object sender, CancelEventArgs e)
  2. {
  3. if (String.IsNullOrEmpty(textBox1.Text))
  4. e.Cancel = true;
  5. }
not just for null value, i need to make sure only numbers are inserted.

thanks in advance for any help
Mar 31 '09 #1
2 6403
tlhintoq
3,525 Expert 2GB
TIP: When you are writing your question, there is a button on the tool bar that wraps the [code] tags around your copy/pasted code. It helps a bunch. Its the button with a '#' on it. More on tags. They're cool. Check'em out.

Option A: Change the Textbox for a NumericUpDown

Option B: Create a custom Textbox, inheriting from Textbox that filters on the Keypress event and only allows numbers to be entered.

Option C: Parse your text in a loop character by character to make sure each one is a number.

Option D: Regular Expressions (RegEx)
Mar 31 '09 #2
orked
49
you can make validation on text box from toolbox ,choose validation if you want write number only choose regular expression validator and write in its properties
(validation expression)this expression(\d{numbers of numbers you want to enter it })
if you refuse null value this expression make what you want.
Good luck.
Apr 1 '09 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Pham Nguyen | last post by:
Has anyone seen an example of a textbox server control that has built-in client-side validation? I'd like to build a server control that extends the System.Web.UI.WebControls.TextBox class to allow...
1
by: Kum | last post by:
Hi, I need help in asp.net dynamic textbox controls validation. I am creating textbox controls dynamically on a asp.net webpage. Now after creating the textboxes on the page I want to validate...
2
by: Oleg Ogurok | last post by:
Hi there, I have a modified ASP.NET TextBox control that formats its output as the phone number, e.g. if you enter "1234567890" it'll change the value to "123-456-7890". This is done by a...
14
by: teddysnips | last post by:
WINDOWS FORMS I've a form that has a textbox that allows the user to enter a string. On the LostFocus event, the textbox formats the string into a preferred format. However, if the user...
1
by: bsm | last post by:
I have created one User controls which contains 1. Textbox and 2. ImageButton (to display calendar) (I tried to create my own datetime control). I have created "onblur" event on textbox event,...
0
by: Mike | last post by:
So here's the situation (.NET 2.0 btw): I have a form, and on this form is a textbox among many other databound controls. The textbox is bound to a field in a data table via the Text property. ...
2
by: Christian Cambier | last post by:
Hello, I have a textbox in which I only want to display numbers when the focus is set on the textbox and the user presses a key on the kb. Easy with html-control <input id="htmlTxtVal2"...
9
mageswar005
by: mageswar005 | last post by:
Hi Guys, My array textbox validation is not working fine,my code is given below please help me immediately. function validation() { var chks =...
2
by: mrutyunjaya | last post by:
hello, i have two textbox column and one button control in gridvie when i click button it will ask plese enter price in first textbox . when enter values it is asking again. how to pass...
4
by: HenrikL | last post by:
Hi. I have a textbox that have a binding on it with converter and validationrules. When a validation error ouccur the foreground of the textbox will change to red cause it has a style.triggers...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.