Javascript Regex Expression Challenge
Jul 18, 2006
I am looking out for a regular expression that takes the following format
textfile_20060711_113441.txt
where
textfile = name of the file
2006 = year
07=month
11=day
11=hour
34=minute
41=seconds.
.txt is extension
The file always comes in the same format. however we need to implement checks so that user doesnt enter invalid month/day/hour/minute etc.
I have created the following regular expression
textfile_(?<Year>(?:d{4}|d{2}))(?x)(?<Month>d{1,2})(?<Day>d{1,2})_([01]?[0-9]|[2][0-3])([0-5][0-9])([0-5][0-9]).[a-zA-Z]{3}
Can anyone guide me as to how do i modify this regex to suit my requirement. This regex currently is not able to handle invalid months or days etc.
Also i do not know how to integrate this regex in my javascript. Pointers or examples will be helpful.
View 2 Replies
ADVERTISEMENT
Aug 30, 2011
I seem to have come across a weird issue in internet explorer.I've been working on doing regular expressions for a register form, and I've checked it in Firefox, and Chrome and it seems to work for both of them but yet it doesn't work for Internext Explorer 6 - 8.The issue is that the drop down boxes (select fields) dont seem to be recognised for RegEx in I.E. this is causing an issue for me as I want it to work in ALL common web browers as well as keeping the whole form standard.
I've pasted a snippet of code below to show you what I've done.This one below is the original one which just checks if the field entry is blank
function check(theForm)
{
var checker;[code]...
If you have any Ideas about what I can do to make it work in I.E. I would be most greatful. Also if anyone knows how to do and RegEx on a checkbox that would help me quite a bit too.
View 9 Replies
View Related
Jul 23, 2005
I have a function which validates the password if there is a number:
-------------------------------------------------
function findNumeric(str_obj){
regEx = /d/;
if (str_obj.match(regEx))
return true;
else
return false;
}
--------------------------------------------------
The problem arises when I put a password with a space in between e.g:
'test test1'. The fucntion returns false. I've tried 's' in the
regEx but the user can put the space anywhere..
Any idea how to solve this problem as I should be able to put any
alplanumeric value into the password, including space.
View 6 Replies
View Related
Jul 23, 2005
I have a variable named "acct". I first want to remove any "-" characters
from it's value. After this I want to verify that we have only exactly 12
digits in the variable.
Unfortunately I'm pretty green as far as using RegEx.
/d{12}/.test(acct); should do the second part, but how do I do the first?
View 4 Replies
View Related
Dec 21, 2004
In have a string of data like so:
<div id="feedback">
<p>[DEC 12th Anthony]I like it[DEC 12th Anthony]I agree</p>
</div>
I'm trying to use regex to add a <br /> before each item in hard brackets so the comments are broken out. Here's what I've tried.
re = /(.*])/gi;
vTemp = aSourceObject.innerHTML.replace(re,"<br />$1");
What I end up getting is:
<div id="feedback">
<p><br />[DEC 12th Anthony]I like it[DEC 12th Anthony]I agree</p>
</div>
It gets it right, but only for the first item, not the second one. If I tell it to put the <br /> after then I get
<p>[DEC 12th Anthony]I like it[DEC 12th Anthony]<br />I agree</p>
So its like its reading the entire section in brackets as one match instead of 2 seperate matches..
View 2 Replies
View Related
Nov 15, 2006
I need information about javascript & regular expression.please suugest me any book or tutorial web site.
View 2 Replies
View Related
Mar 20, 2007
I have a little Ajax script and I'm trying to remove some CSS elements from a DIV tag and I'm have a bit of trouble with the Regex. Right now I'm trying to remove the z-index attribute. It can look something like any of these:
z-index: 1000;
z-index: 0;
z-index: 75;
etc...
Here's what I'm using right now:
document.getElementById('right_column').innerHTML.replace(/z-index: [0-9]; /gi, "replaced"));
It replaces z-index: 0; just fine but I can't find the correct modifiers to make it work for 2, 3 or 4 digit z-indexes.
View 2 Replies
View Related
Mar 30, 2006
I am using Regular Expressions and Javascript to validate a form,
specifically I want to make sure that if they try to upload a file that
it has a proper name w/ certain extensions (doc,pdf, rtf). The script
works on IE and Mozilla but fails on Safari on the MacOSX. Here is my
code..
// ok files with proper extension
var reOKFiles = /^([a-zA-Z].*|[1-9].*).(doc|DOC|pdf|PDF|rtf|RTF)$/;
//where i check for the file...
if(window.document.myForm.myDocument.value != ""){
var fileStr = window.document.myForm.myDocument.value;
if(!reOKFiles.test(fileStr)){
alert("Please try again, you tried to upload an invalid file type
for CRITERIA 1");
window.document.myForm.myDocument.focus();
return (false);
View 6 Replies
View Related
Jul 23, 2005
Coding patterns for regular expressions is completely unintuitive, as far
as I can see. I have been trying to write script that produces an array
of attribute components within an HTML element.
Consider the example of the HTML element TABLE with the following
attributes producing sufficient complexity within the element:
<table id="machines" class="noborders inred"
style="margin:2em 4em;background-color:#ddd;">
Note that the HTML was created as a string in code, and thus there are NO
newlines ('
') in the string, as if a file was parsed...so newlines are
not an issue. The only whitespace is the space character ' ' itself,
required to delimit the element components.
I want to write an RE containing paranthesized substring matching that
neatly orders attribute components. The resulting array, after the
execution of the string .match() method upon the example, should look as
follows:
attrs = [ "id", "machines", "class", "noborders inred", "style",
"margin:2em 4em;background-color:#ddd;" ]
I can then march down the array (in steps of 2) setting attributes
(name=value) to the element using standard DOM interface methods, right?
In approaching the writing of the RE, I have to take into account the
characters permitted to form the attribute name and the attribute value.
I assume a start to the RE pattern as:
<attribute name>=<attribute value>
I then try to find the right RE pattern for <attribute name>, keeping in
mind what the legal characters are for attribute names according to the
HTML standard ("recommendation"):
[A-Za-z0-9-]+
I believe this patterns conforms to the standard for attribute values:
[,;'":!%A-Za-z0-9s.-]+
That pattern tries to be more exclusive than inclusive, although I think
just about every character on the planet, including a newline, is
acceptable in an attribute value, at least the kind one might see in an
HTML document. Code:
View 7 Replies
View Related
May 13, 2010
I am using an HV Menu and want to be able to overlap the parent menu over the background image used for the menus. Each menu item has a background image and I would like the menu to open overlapping this image. Not sure how to do this but am pretty sure it is in the menu_com.js file.
View 1 Replies
View Related
Jul 23, 2005
I have got a bookmarklet for use with Opera which highlights all
occurrences of some text in the displayed page. I find it very
useful.
Sometimes I need to use two or three different colours for different
keywords I want highlighting on the same page. I have done this by
changing the original word 'yellow' for other javascript colour
words.
I know next to nothig about javascript. So I would ask if anyone
knows how I can tweak this javascript bookmarklet code (see below) in
two sepearte ways:
(1) So that I can select a color from a list. This may be as simple
as changing the caption to say "enter 1 for lime, 2 for yellow," etc.
or it might be cleverer.
(2) This is mutually exclusive with (1). In this case the
javascript would prompt me to enter a javascript colour keyword (like
"yellow" or colour code like "FF00FF").....
View 3 Replies
View Related
Jul 23, 2005
I'm trying to perform a very simple validation of user input. I
want to verify that the user entered a six-digit string consisting
entirely of numbers. So anything from 000000 to 999999 is considered
valid. The problem that I'm having is getting the validation to work on
the entire string. In other words, 000000 is okay but 000000000000 is
also returning as a match. Here's a quick code block...I have something
along these lines....
/*********************/
<html>
<body>
<INPUT name="txtNumberField" type="text" id="txtNumberField">
<INPUT onClick="fnTestNumberField()" id=Button1 type=button value="Test
Number!" name=btnTest>
<script language=javascript>
function fnTestNumberField()
{
var sNumberValue = document.getElementById("txtNumberField").value;
if (sNumberValue.match(/A[0-9]{6}z/))
{
alert("match");
} else {
alert("no match");
}
}
</script>
</body>
</html>
/******************/
That is failing when I enter 123456 into the textbox. Why, though? I
know I can replace...
if (sNumberValue.match(/A[0-9]{6}z/))
....with something like...
if (sNumberValue.length == 6 && sNumberValue.match(/[0-9]{6}/))
....or I could assign a maxlength to the input box, of course. The thing
is, I really want to know WHY the regular expression isn't responding
as I'd expect. Is there a syntax error somewhere in the code?
View 2 Replies
View Related
Jun 3, 2010
JavaScript Challenge Play--Random Color (The English Version of JavaScript)
Write a function to return a string that can represents a color.
Requirements:
1. The color is random. The color string can be similar to "cf9c63", also similar to "rgb (211,100, 180)".
2. Code should be concise, clear, easy to read, good performance, and better than my solution.
And go to [url] to see more!
View 1 Replies
View Related
Jan 9, 2006
Basically i want to get the current url, and then replace http:// with
something else.
Here is the current code.
var current_url = window.document.location;
var re = new RegExp("http://", "g");
if(re.test(current_url)) {
me = current_url.replace(re,"http://www.addme.com/");
window.alert("found :: " + me + " :: " + current_url);
} else {
window.alert("not");}
if my page was http://ww.google.com 'd get the alert to be:
found :: undefined :: http://www.google.com.
I dont understand why i am getting undefined. When re.test() works.
surely that means the regex is correct.
View 14 Replies
View Related
Jun 15, 2006
Trying to match the entire following object literal code using a RegEx.
var Punctuators = { '{' : 'LeftCurly', '}' : 'RightCurly' }
Variations on the idea of using /var.*{.*}/ of course stops at the
first }.
View 7 Replies
View Related
May 9, 2007
I was using the following code:
element.value = element.value.replace(/ /g,'');
to remove all the spaces in a string.
However in IE6 it complained with and "Expected ')'" error.
How can I tell IE6 to replace just spaces (i.e. not using s)?
I tried / / and /[ ]/ but neither of them worked either.
View 13 Replies
View Related
May 18, 2007
I need to strip everything from a file except what is between <body>
and </body>
View 2 Replies
View Related
Oct 13, 2009
ok heres a regex
/^(?=.*d)(?=.*[A-Z])(?=.*[a-z]).{8,16}$/
which checks I have at least one lowercase letter, one uppercase letter and one number and the string is between 8 and 16 characters.I have adapted this from another source and it works as intended on all browsers but not IE7 or IE6 (oh microsoft why do you make my life so hard)This works fine in all other browsers (IE8 is fine) but doesnt work in IE6 or IE7
View 1 Replies
View Related
Oct 23, 2005
I'm writing an ECMAScript tokeniser and parser and trying to find out if I can eliminate the switching from tokenising "/" as start of regex or the division operator depending on the parser feedback - essentially, if I can make the tokeniser independent of the parser. (I have a gut feeling this needs too much special casing to be worth it). Code:
View 2 Replies
View Related
Jun 27, 2010
I have been playing with this regex for a few hours now I want to make it so it accepts commas also.
At the moment it works with A-z and - . ' but can't seem to figure out how to include commas.
View 4 Replies
View Related
Jun 21, 2011
I have a bunch of text that I want to split into an array of sentences. I have the following code that works just fine on FF and Chromium, but ofc has to fail on the pile of *** that is IE [code]...
It does not produce any errors, but the resulting array often has empty strings as value instead of the sentences that should be there. how to do this in a way it also works on IE?
View 1 Replies
View Related
Oct 27, 2004
i have the following regex:
(s*{s*(<?)s*(>?)s*}s*)
this needs to be able to match a string and make the following replacements:
if the string matches without < or >, replace the match with a space, a replacement string, and another space. if < matches also, do not add the left space. if > matches, do not add the right space. if < and > match, do not add the beginning or ending space
Old {} String => Old Replacement String
Old {<} String => OldReplacement String
Old {>} String => Old ReplacementString
Old {<>} String => OldReplacementString
this will have to be done a LOT of times, so efficiency is very important the answer in php is below. can anyone help me figure out how to do it in javascript? PHP Code:
View 4 Replies
View Related
Jul 21, 2010
How would I get this variable to allow whitespace?
var illegalChars = /W/; // allow letters, numbers, and underscores
View 11 Replies
View Related
Jul 23, 2005
I need to write a function that will remove a specified parameter from a
URL. For example:
removeParam("param1", "http://mysite.com/mypage.htm?param1=1¶m2=2");
would return:
"http://mysite.com/mypage.htm?param2=2"
I'm thinking that string.replace(/regex/, ""); would do the trick, but how
do I construct a correct regex?
I see a problem if the parameter name ("param1") happens to contain any
characters that have a special meaning in a regular expression.
View 3 Replies
View Related
Jul 23, 2005
I don't know where the actual issue is, but hopefully someone can explain.
The following displays "5" in FireFox, but "3" in IE:
<script type="text/javascript" language="javascript">
var newString = ",a,b,c,";
var treeArray = newString.split(/,/i);
alert(treeArray.length);
</script>
View 1 Replies
View Related
Sep 28, 2005
I have a string I have to parse
AB1.2CD34
I need to split the string into groups of letters and numbers..
"AB" "1.2" "CD" "34"
What is the best way of doing this ?
I've looked at string.split using a regex, but that doesn't output the
delimiters.
View 3 Replies
View Related