Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
nbv4
Aug 21, 2002

by Duchess Gummybuns
I found a regular expression that seems to work when I test it out using this page: http://tools.netshiftmedia.com/regexlibrary/

But when I try to use it in my script, I'm getting an error. What am I doing wrong? Here is my code:

code:
var date_regex = (?=\d)^(?:(?!(?:10\D(?:0?[5-9]|1[0-4])\D(?:1582))|(?:0?9\D(?:0?[3-9]|1[0-3])\D(?:1752)))((?:0
?[13578]|1[02])|(?:0?[469]|11)(?!\/31)(?!-31)(?!\.31)|(?:0?2(?=.?(?:(?:29.(?!000[04]|(?:(?:1[^0-6]|[2468][^048]
|[3579][^26])00))(?:(?:(?:\d\d)(?:[02468][048]|[13579][26])(?!\x20BC))|(?:00(?:42|3[0369]|2[147]|1[258]|09)\x20
BC))))))|(?:0?2(?=.(?:(?:\d\D)|(?:[01]\d)|(?:2[0-8])))))(\/)(0?[1-9]|[12]\d|3[01])\2(?!0000)((?=(?:00(?:4[0-5]|
[0-3]?\d)\x20BC)|(?:\d{4}(?!\x20BC)))\d{4}(?:\x20BC)?)(?:$|(?=\x20\d)\x20))?((?:(?:0?[1-9]|1[012])(?::[0-5]\d){
0,2}(?:\x20[aApP][mM]))|(?:[01]\d|2[0-3])(?::[0-5]\d){1,2})?$;
	
	if ((date_regex.test(date)) || (date != ''))
	{
		alert('Invalid date');
		return false;
}

I'm getting a syntax error on the line where the regex variable is defined. I'm thinking I need to tell javascript that that big long line of text is a regex, because I think the error is caused by it thinking I'm forgetting quotation marks, or something. All the examples I've seen where regex's are used in javascript, they've just been bare like how I have it...

edit: long line broken up to prevent page breaking, the actual code does not have the line broken up

Adbot
ADBOT LOVES YOU

nbv4
Aug 21, 2002

by Duchess Gummybuns

Avenging Dentist posted:

You need to surround the regex with slashes, like you would in Perl.

Also why in god's name do you have a regex like that? I think when you have to worry about table breaking with a regex, you might want to look into writing a grammar to do whatever it is you're doing (possibly hard in Javascript unless there's a library for it). The benefit of a grammar is that it isn't write-only code. :)

Why waste time writing a complicated function when you can just find a regex via google and plop it in?

edit: by the way, adding slashes doesn't fix it either. I'm now getting an "unterminated regular expression literal" error. I've now tried 3 or 4 different regex's I've found with Google, and they either give me a syntax error, or they parse fine, but return false every time. this is starting to piss me off.

nbv4 fucked around with this message at 18:43 on Mar 4, 2008

nbv4
Aug 21, 2002

by Duchess Gummybuns

6174 posted:

Avenging Dentist didn't suggest adding backslashes. He suggested slashes, aka forward slashes.

gah, I have a habit of calling either back slashes or front slashes "backslashes". I tried adding front slashes and it gave me the "unterminated regular expression literal" error. Backslashes gave me a syntax error.

nbv4
Aug 21, 2002

by Duchess Gummybuns

Avenging Dentist posted:

It works fine for me. You're doing the following right?
code:
var date_regex = /[i]blahblahblahblah[/i]/;



this is the exact error I get. And here is the top few lines of my code:

code:
function validate_new_entry_form() 
{

	var route = document.forms[0].route.value;
	var total = document.forms[0].total.value;
	var date = document.forms[0].date.value;
	
	var day_landings = document.forms[0].day_landings.value;
	
	var night_landings = document.forms[0].night_landings.value;
	
	var date_regex = /(?=\d)^(?:(?!(?:10\D(?:0?[5-9]|1[0-4])\D(?:1582))|(?:0?9\D(?:0?[3-9]|1[0-3])\D(?:1752)))((?:0
?[13578]|1[02])|(?:0?[469]|11)(?!\/31)(?!-31)(?!\.31)|(?:0?2(?=.?(?:(?:29.(?!000[04]|(?:(?:1[^0-6]|[2468][^048]
|[3579][^26])00))(?:(?:(?:\d\d)(?:[02468][048]|[13579][26])(?!\x20BC))|(?:00(?:42|3[0369]|2[147]|1[258]|09)\x20
BC))))))|(?:0?2(?=.(?:(?:\d\D)|(?:[01]\d)|(?:2[0-8])))))(\/)(0?[1-9]|[12]\d|3[01])\2(?!0000)((?=(?:00(?:4[0-5]|
[0-3]?\d)\x20BC)|(?:\d{4}(?!\x20BC)))\d{4}(?:\x20BC)?)(?:$|(?=\x20\d)\x20))?((?:(?:0?[1-9]|1[012])(?::[0-5]\d){
0,2}(?:\x20[aApP][mM]))|(?:[01]\d|2[0-3])(?::[0-5]\d){1,2})?$/
	
	if (total <= 0)
	{
		alert('Total time can not be 0');
		return false;
	}
	else if (!date_regex.test(date))
	{
		alert('Invalid date');
		return false;
	}

nbv4
Aug 21, 2002

by Duchess Gummybuns

Avenging Dentist posted:

Get rid of the newlines in the regex (obviously don't do this in the post :)).

aw super, that did the trick. I feel dumb now.

nbv4
Aug 21, 2002

by Duchess Gummybuns
I have a form on a webpage that has like 50 checkboxes. I'm using a javascript function to validate the form. I'm trying to formulate an IF statement that returns true if there are more than one of those boxes checked. I'm thinking the XOR operator would be best in this situation, but apparently javascript doesn't have a xor operator... This is what I'm kind of wanting to do:

code:
if(checkbox1 ^^ checkbox2 ^^ checkbox3 ^^ checkbox4 ... )
    alert("you can't check more than one box");
and no, using radio buttons instead is not a proper solution.

I found this page, which talks about this issue, but it quickly degrades into moon language with exclamation marks and carrots everywhere. Whats the cleanest way to do this?

nbv4
Aug 21, 2002

by Duchess Gummybuns
Is there an easy way to debug javascript on IE? My site works fine in mozilla browsers, but literally none of the javascript functions work in IE. All IE gives me is a vague "invalid argument" type error which makes it hard to figure out whats wrong.

nbv4
Aug 21, 2002

by Duchess Gummybuns

fletcher posted:

IE8 has a development mode that is like a lovely version of Firebug. You can also emulate IE7 with it.

Is the the only way? How do people debug JavaScript from within a UNIX environment?

nbv4
Aug 21, 2002

by Duchess Gummybuns

Avenging Dentist posted:

Does anyone in the world actually do web development exclusively in UNIX?

Also, have you seen http://www.jonathanboutelle.com/mt/archives/2006/01/howto_debug_jav.html ?

I do all my programing in Ubuntu. Every few days I'll load my stuff onto my laptop which runs XP too see how it looks, which is kind of a pain.

I came across that script debugger, but I'm not about to pay hundreds of dollars to buy Office, just for that one tiny application.

nbv4
Aug 21, 2002

by Duchess Gummybuns
Can someone explain to me the purpose of putting "java script:" at the begining of a function when running a javascript function from within html? For instance:

code:
<span onclick="javascript:set_something('12');">click here to set something</span>
Its not the kind of thing you can google easily...

nbv4
Aug 21, 2002

by Duchess Gummybuns
code:
for(field in fields) {
		
	$("#button_" + field).click(function(event) {
		
		if( $("#id_" + field).val() == "") {
			$("#id_" + field).val($("#id_total").val());
		} else {
			$("#id_" + field).val("");
		}
	});
}
How can I get this little javascript code to work. The problem has to do with variable scope, I'm sure. Basically I want to create a bunch of jQuery objects through a loop.

nbv4
Aug 21, 2002

by Duchess Gummybuns
I have this simple problem that I just can't figure out. I have a 256 square pixel image. The left and right borders corresponds to a longitude value, and the top abd bottom edge corresponds to a lattitide value. Basically the 256 square image is a rectangle laid onto a map. If you have a lat/long value that lied inside the rectangle, how do you get the pixel coordinates of that point? I've been messing with this all morning, but I just can't seem to find a formula that works.

nbv4
Aug 21, 2002

by Duchess Gummybuns

Avenging Dentist posted:

code:
x = (longitude - min_long) / (max_long - min_long) * width

the only problem is that doesn't even begin to work anywhere but the north eastern hemisphere.

nbv4
Aug 21, 2002

by Duchess Gummybuns
nevermind

nbv4 fucked around with this message at 07:04 on May 29, 2009

nbv4
Aug 21, 2002

by Duchess Gummybuns

rjmccall posted:

Do you have some sort of misplaced fetish for abs? I have no idea what you think you're doing with that calculation.

code:
lonWidth = E - W
if E < W:
  lonWidth += 360
lonScale = width / lonWidth
latScale = height / (N - S)

for base in bases:
  lon = base.location.y
  lat = base.location.x
  if lon < W:
    lon += 360
  x = (lon - W) * lonScale
  y = (lat - S) * latScale   # using Cartesian coordinates
  ...
I was just trying random crap in a desperate attempt to get it working. I got it working now. The problem was the way PIL adds the icon. I had to do:

code:
im.paste(icon, (256-x, y))

nbv4
Aug 21, 2002

by Duchess Gummybuns
nm

nbv4 fucked around with this message at 03:07 on Jun 27, 2009

nbv4
Aug 21, 2002

by Duchess Gummybuns
A long time ago I read about this method where you can store many boolean values as an integer value by multiplying a bunch of prime numbers together. Does anyone know what this method is called? For instance if you want to store

a=true
b=false
c=false
d=true
e=true

you go:

a=2
b=3
c=5
d=7
e=11

a * d * e = 2 * 7 * 11 = 154

then to go back to booleans, you factor the number and get:

2*7*11 which correlates to a=true, d=true, e=true

Whats this method called?

nbv4
Aug 21, 2002

by Duchess Gummybuns

Dijkstracula posted:

I don't know the name of such a thing, but why on earth would you want to use that instead of a bit field? Suddenly extracting values becomes Hard-With-A-Capitol-H rather than a simple mask and shift.

Instead of creating a table in my database with a bunch of boolean columns, I can store all the information in one bigint. This way if I want to add a new boolean, instead of creating a new column in my table, I can just factor in a new prime. The only problem is that it would probably overflow the integer after so many primes...

The method I remember reading about may have used addition, because I remember it being used with like 40 different booleans.

nbv4 fucked around with this message at 21:07 on Aug 1, 2009

nbv4
Aug 21, 2002

by Duchess Gummybuns
whats a good 'turnkey' blog hosting service for a programming blog? I want something that I don't have to host myself, and can do things like syntax highlighting out of the box.

Adbot
ADBOT LOVES YOU

nbv4
Aug 21, 2002

by Duchess Gummybuns
Can anyone recommend me a good postal address verification service? I want to be able to enter an address, and have it return True or False depending on whether the address is in the postal database. Bonus points if it will return a 'cleaned' version of the data passed in if it is slightly off. I've tried CDYNE, but it sucks. Google has a geocoder, but the terms disallow usage outside of a google maps applet.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply