I have created a regular expression to validate dates in MM/DD/YYYY, MM/YYYY, and YYYY. "((0[1-9]|1[012])[/]((0[1-9]|[12][0-9]|3[01])[/])?)?(19|20)\d\d " . How can I make this expression work with a multi-line textbox, so that a user would be able to enter multiple dates (each on a new line) and still be validated by my expression.
Example: 3 dates entered into textbox, all be validated by expression.
Multi-Line TextBox:
01/01/2008
01/2007
2006
7 2522
I have created a regular expression to validate dates in MM/DD/YYYY, MM/YYYY, and YYYY. "((0[1-9]|1[012])[/]((0[1-9]|[12][0-9]|3[01])[/])?)?(19|20)\d\d " . How can I make this expression work with a multi-line textbox, so that a user would be able to enter multiple dates (each on a new line) and still be validated by my expression.
Example: 3 dates entered into textbox, all be validated by expression.
Multi-Line TextBox:
01/01/2008
01/2007
2006
Well, you can split the input by newline, then use a for each loop to validate each one. Although, I'd wonder if you shouldn't just use a date-time picker to populate a listbox-- then you wouldn't need to validate it yourself because the date-time picker returns a date data type.
I'm using a RegularExpressi onValidator.
here is sample code - protected void Page_Load(object sender, EventArgs e)
-
{
-
-
TextBox textBox1 = new TextBox();
-
textBox1.ID = "textBox1";
-
textBox1.TextMode = TextBoxMode.MultiLine;
-
textBox1.Rows = 10;
-
form1.Controls.Add(textBox1);
-
-
Button SubmitButton = new Button();
-
SubmitButton.ID = "SubmitButton";
-
SubmitButton.Text = "Submit";
-
SubmitButton.Click += new EventHandler(SubmitButton_Click);
-
form1.Controls.Add(SubmitButton);
-
-
RegularExpressionValidator datevalidator = new RegularExpressionValidator();
-
datevalidator.ControlToValidate = "textBox1";
-
datevalidator.Text = "Enter Correct Date";
-
datevalidator.ValidationExpression = @"((0[1-9]|1[012])[/]((0[1-9]|[12][0-9]|3[01])[/])?)?(19|20)\d\d";
-
form1.Controls.Add(datevalidator);
-
-
}
-
-
private void SubmitButton_Click(object sender, System.EventArgs e)
-
{
-
//Get output from textbox
-
//Value output will look like : "value1\r\nvalue2\r\nvalue3"
-
}
I'm using a RegularExpressi onValidator.
here is sample code - protected void Page_Load(object sender, EventArgs e)
-
{
-
-
TextBox textBox1 = new TextBox();
-
textBox1.ID = "textBox1";
-
textBox1.TextMode = TextBoxMode.MultiLine;
-
textBox1.Rows = 10;
-
form1.Controls.Add(textBox1);
-
-
Button SubmitButton = new Button();
-
SubmitButton.ID = "SubmitButton";
-
SubmitButton.Text = "Submit";
-
SubmitButton.Click += new EventHandler(SubmitButton_Click);
-
form1.Controls.Add(SubmitButton);
-
-
RegularExpressionValidator datevalidator = new RegularExpressionValidator();
-
datevalidator.ControlToValidate = "textBox1";
-
datevalidator.Text = "Enter Correct Date";
-
datevalidator.ValidationExpression = @"((0[1-9]|1[012])[/]((0[1-9]|[12][0-9]|3[01])[/])?)?(19|20)\d\d";
-
form1.Controls.Add(datevalidator);
-
-
}
-
-
private void SubmitButton_Click(object sender, System.EventArgs e)
-
{
-
//Get output from textbox
-
//Value output will look like : "value1\r\nvalue2\r\nvalue3"
-
}
Is this for an assignment? If so, do it to your specs. I'm just saying that you never want to reinvent the wheel. The date-time picker gives you a valid date, so you wouldn't have to validate it yourself. If the idea is that the user will be entering so many dates that the dtp would be cumbersome, you may want to look ate date.TryParse() .
BTW, why create the controls at run time? Especially if you're doing this in the load event, you might as well optimize performance and create the controls at design time.
EDIT:
I forgot that what is being inputed might not be only the year. I'm not sure that TryParse would be successful with such an input. So, like I said before, split the text of the text box by the newline character, trim any spaces, then use a foreach to validate each line using your regex.
Is this for an assignment? If so, do it to your specs. I'm just saying that you never want to reinvent the wheel. The date-time picker gives you a valid date, so you wouldn't have to validate it yourself.
BTW, why create the controls at run time? Especially if you're doing this in the load event, you might as well optimize performance and create the controls at design time.
No, I'm working a proof of concept for a business project. The reason I can't use the datetime picker is because the data that will be inputed in either MM/DD/YY, MM/YYYY, or YYYY.(this is document metadata, so it's need to be inputed as is) As for the code it's just a crappy concept I made to mess with the expression. What I am trying to figure out is how to get the RegularExpressi onValidator to validate my input when the user enters multiple dates in a multi-line textbox.....
No, I'm working a proof of concept for a business project. The reason I can't use the datetime picker is because the data that will be inputed in either MM/DD/YY, MM/YYYY, or YYYY.(this is document metadata, so it's need to be inputed as is) As for the code it's just a crappy concept I made to mess with the expression. What I am trying to figure out is how to get the RegularExpressi onValidator to validate my input when the user enters multiple dates in a multi-line textbox.....
I know nothing of the RegularExpressi onValidator.
I've only used the .NET RegEx object. To validate if a string is accepted by your regular expression, first declare a RegEx object:
RegEx MyRegEx = new RegEx(MyStringR epresentationOf MyRegularExpres sion);
Then, too see if a string is validated:
MyRegEx.IsMatch (StringToBeVali dated);
I know nothing of the RegularExpressi onValidator.
I've only used the .NET RegEx object. To validate if a string is accepted by your regular expression, first declare a RegEx object:
RegEx MyRegEx = new RegEx(MyStringR epresentationOf MyRegularExpres sion);
Then, too see if a string is validated:
MyRegEx.IsMatch (StringToBeVali dated);
somebody help me on another forum.. FYI, here is the answer:
(((0[1-9]|1[012])[/]((0[1-9]|[12][0-9]|3[01])[/])?)?(19|20)\d\d (\s+)?)+
somebody help me on another forum.. FYI, here is the answer:
(((0[1-9]|1[012])[/]((0[1-9]|[12][0-9]|3[01])[/])?)?(19|20)\d\d (\s+)?)+
Next time, say that you need help with the regular expression itself. I assumed that you had a valid re and merely wanted to know how to validate a string with it. The unix forum is a better place for this question.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Mark |
last post by:
To validate the length of a multiline textbox, I'm told that I have to use a
regular expression validator. The regular expression below limits it to 25
characters in length, but if the user enters a hard return, it bombs
regardless of length. How do you allow hard returns in the following
regular expression? Thanks in advance!
^.{0,25}$
...
|
by: VSK |
last post by:
Hi all,
I have a .ascx file with
dropdownbox (SSN, EmpName)
textbox
submit button
regular expression validator( controltovalidate is the above textbox)
Now i want to change the Regular Expression of the validator based on the
|
by: S.Kartikeyan |
last post by:
I have the following problem.
I am using the follwing Regular Expression validator(REV) with validator expressions
^{1,2}$
^{3,20}$
The idea of the first exp is 1 or 2 digits
the idea of second expression is username between 3 and 20 chars
When the user enters characters other than the specified REVs are working.
But if the user leaves...
|
by: Dot net work |
last post by:
Hello.
Say I have a .net textbox that uses a .net regularexpressionvalidator.
If the regular expression fails, is it possible to launch a small
client side javascript function to do something, such as change the
border color of the textbox to red? That would look quite nice: if
the expression fails, the red validator text is shown, plus...
|
by: Chris Kennedy |
last post by:
Does anyone know a regular expression that will validate the file extension
but also allow multiple file extensions if necessary. It also needs to be
case insensitive. Basically, what I want is to validate a file input box to
check if the extension is the correct type, i.e. .doc for a Word Document
etc. Also I would like to check multiple file...
| |
by: Kerry |
last post by:
Please help.
I need a regular expression that parses a stream of up to 450 characters
into 15 separate strings of up to 30 characters each. The regex must break
at newlines. Ideally, the regex will "word wrap" that is, not break in the
middle of words. I have the following:
(?m:(?:(.)?){1,30}\s\n?){1,15}?
This works well as long as...
|
by: David |
last post by:
I'm having trouble getting the regular expression validator to work
with a text box.
In this simple example I only want lower case letters to be allowed.
So I tried the following and it doesn't work, would somebody be so
kind as to tell me why.
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator...
|
by: Joey |
last post by:
Hello guys, I'm trying to learn about regular expressions. I need to
be able to use an RE that can evaluate for STRINGS (or specific
sequences of characters), not just occurances of characters.
Everything I have read thus far involves checking only for the
presence or absence of characters. Can anyone provide an RE that will
correctly...
|
by: durga2005 |
last post by:
hi
i just added one textbox and regular expression validator in the form and set the properties for regular expression validator control.
then i placed these two controls inside update panel . when i execute this, the validation was not working
before placing in update panel validation was working
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it. ...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |