hi there
it seems to be simple but i do not know why my java script function does not work. - function validatePartialDateInput(SourceField, FieldLabel) {
-
-
var sField = document.getElementById('ctl00_ContentPlaceHolder1_'+ SourceField);
-
-
var regex_dt = '/^\d{1,2}[/]\d{4}$/';
-
alert((sField.value));
-
alert(regex_dt.match(sField.value));//returns null
-
if(sField.value.length > 0)
-
{
-
if (regex_dt.match(sField.value))
-
{
-
alert(sField.value);
-
alert(FieldLabel);
-
}
-
}
-
}
the regex.match returns null....I have no clue why....can somebody please throw some light on this..thank you
If you use RegExp to create your regular expression, you don't use the regular expression delineators. And if you're using RegExp, you need to escape all forward slashes. var regex_dt = new RegExp('(0[1-9]|1[012])[- /.](19|20)\\d\\d', ""); 8 8083
You haven't created a regex object. All you have there is a string.
thank you..i thought if it is java script I don't have to create a object.
anyways, when I created the object it worked... - var regex_dt = new RegExp('/^\d{1,2}[/]\d{1,4}$/',"");
however, my regex always returns false.. - function validatePartialDateInput(SourceField, FieldLabel) {
-
-
var sField = document.getElementById('ctl00_ContentPlaceHolder1_'+ SourceField);
-
-
var regex_dt = new RegExp('/^(0[1-9]|1[012])[- /.](19|20)\d\d$/',"");
-
alert((sField.value));
-
alert(regex_dt.test(sField.value));//always returns false
-
if(sField.value.length > 0)
-
{
-
if (!regex_dt.test(sField.value))
-
{
-
alert(FieldLabel);
-
}
-
}
-
}
i have changed my regex to , '/^(0[1-9]|1[012])[- /.](19|20)\d\d$/' to validate mm/yyyy. it always returns false....thank you
If you use RegExp to create your regular expression, you don't use the regular expression delineators. And if you're using RegExp, you need to escape all forward slashes. var regex_dt = new RegExp('(0[1-9]|1[012])[- /.](19|20)\\d\\d', "");
thank you for the reply but still no use....
I missed the closing quote on the regex string. Put that back in and it should work.
I do have the closing quote...anyways, this is what i have now... - function validatePartialDateInput(SourceField, FieldLabel) {
-
-
var sField = document.getElementById('ctl00_ContentPlaceHolder1_'+ SourceField);
-
-
var regex_dt = new RegExp('^(0[1-9]|1[012])[- /.](19|20)\d\d$',"");
-
alert((sField.value));
-
alert(regex_dt.test(sField.value));
-
if(sField.value.length > 0)
-
{
-
if (!regex_dt.test(sField.value))
-
{
-
alert(FieldLabel);
-
}
-
}
-
}
That's not even what I have in my code. Look again at my post.
I have not taken a closer look at the expression..now it works..thank you....
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Rene van Hoek |
last post by:
Hi,
I am using Xalan 1.8.0 and Xerces 2.6.0 in C++.
I have an XML document which I first transform into an other XML
document using an XSL styelsheet. Then I want to parse with
XPathEvaluator...
|
by: Lee Kuhn |
last post by:
Is there a way to add a literal character to a regex match? For example,
normally applying the regex ..$ to the string "123456" results in a match
"56". I want to be to add a literal character to...
|
by: Jeff McPhail |
last post by:
I am using Regex.Match in a large application and the memory is growing out of control. I have tried several ways to try and release the memory and none of them work. Here are some similar examples...
|
by: DKode |
last post by:
I have the following regex that I am using:
Match match = Regex.Match(global, "%(?<column>.+?)%");
my input string (global) is this:
"something\%username%\somethingelse\%match2%\some\%match3%...
|
by: tdmailbox |
last post by:
I have the following regular expression. It works fine if the regex
code returns a match. However if not the .match code fails.
How can I code this so that it skips the match if the regular...
|
by: Beowulf |
last post by:
If I run this statement in Query Analyzer, it properly returns 1
for my testing table. But if I put the statement into a stored
procedure, the stored procedure returns NULL. What am I doing...
|
by: sherifffruitfly |
last post by:
Hi,
I've been searching as best I can for this - coming up with little.
I have a file that is full of lines fitting this pattern:
(?<year>\d{4}),(?<amount>\d{6,7})
I'm likely to get a...
|
by: Uldis Bojars |
last post by:
Hi All,
I have encountered problems with JS RegExp.exec() and can't find what
is the problem. Could you help me?
formRequest is a function that extracts some information from
XMLHTTPRequest...
|
by: Hrvoje Niksic |
last post by:
I often have the need to match multiple regexes against a single
string, typically a line of input, like this:
if (matchobj = re1.match(line)):
... re1 matched; do something with matchobj ......
|
by: Maurizio Vitale |
last post by:
Has to be something really stupid, but the following never finish
(running Python 2.5.1 (r251:54863, Jan 10 2008, 18:00:49)
on linux2).
The intention is to match C++ identifiers, with or...
|
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
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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,...
|
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,...
|
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: 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...
|
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,...
| |