Forum Moderators: open
Characters 1-2 must be "e3", "c5" or "d7",
Characters 3-4 must be between 52 and 71,
Character 5 must be 8.
It would seem pretty simple to write, but I don't know how to strip the variable down to the the first two, middle, or last characters to see what they equal.
Any ideas? Thanks!
[google.se...]
var str = "what is this";
alert(str.substring(1,3)) // 'ha'
[regexlib.com ]
#2 required a bit of thinking. I generally try to avoid that.
/*-------------------------------------------
1) Characters 1-2 must be "e3", "c5" or "d7",
2) Characters 3-4 must be between 52 and 71,
3) Character 5 must be 8.
---------------------------------------------*/strings =
[
'e3568',/* T */
'c5568', /* T */
'd8568', /* F:1 */
'd7898', /* F:2 */
'c5719' /* F:3*/
]reg = /^(e3¦c5¦d7)(5[2-7]¦6[0-9]¦7[01])8$/g;
for( k=-1; s=strings[++k];)
alert( reg.test(s) );
With the link provided, I was able to write this function:
function reprint(){get_game();if(game_num.slice(4,5)=="8" && game_num.slice(2,4)>"51" && game_num.slice(2,4)<"72") {if(game_num.slice(0,2)=="e3" ¦¦ game_num.slice(0,2)=="c5" ¦¦ game_num.slice(0,2)=="d7") {window.location='pdf/'+game_num+'.pdf';}else{alert("Bad Game Number!");}}else{alert("Bad Game Number!");}}
I know it's probably not the most efficient piece of script out there, but it's a starting point, and it works.
Stooshie, Bernard, I know regular expressions is the way to go, but they are so difficult the figure out, Bernard, thanks for working out the problem, that's awesome!
In the script above, to use the regular expression, would it be something like this:
function reprint(){get_game();if(game_num==/^(e3¦c5¦d7)(5[2-7]¦6[0-9]¦7[01])8$/){window.location='pdf/'+game_num+'.pdf';}else{alert("Bad Game Number!");}}
Thanks again for your feedback!
function reprint(){get_game();var filter = /^(e3¦c5¦d7)(5[2-9]¦6[0-9]¦7[01])8$/;if (filter.test(game_num)) {window.location='pdf/'+game_num+'.pdf';};else {alert("Bad Game Number!");}}
It functions, but it invalidates all numbers. Am I implementing regular expression wrong?
Thanks.