If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

[RESOLVED] form validation

Hi people, me again. sorry!

I have two different criteria for two seperate form feilds both using regular expressions, however for some reason the second one is the only one which is applied. The code ignors the first rule no matter which way round they go. could someone please rewrite for me?

You can't have two function's with the same name.
Might also be useful to see where/how you are trying to call them.

Also, your RegExp for a UK Postcode doesn't look right - the first group is one or two letters, followed by one or two digits... Probably worth having a look on the net for a pre-built expression, as some of the rules can be pretty subtle.

And omnicity picked out the one thing that is going to kill the validation from the start - you canNOT have two functions with the same name in the same document (either typed in or refereced by src.) That's the main thing, right there. Conflict. One gets ignored; assuming it doesn't flat out break.

|||||o . Q
_—__ "You live and you learn; or you don't live long." - Lazarus Long

right ok i see so i need to combine the two together into one function? how would I go about doing this? my javascript knowledge is very patchy im afraid!

Also, your RegExp for a UK Postcode doesn't look right - the first group is one or two letters, followed by one or two digits... Probably worth having a look on the net for a pre-built expression, as some of the rules can be pretty subtle.

thanks for the heads up and i am aware that there are alot more rules which can be applied when validating the postcode, however for what i need it for this rule is all i need. i appreciate your help however.

Some of the London postcodes can be as simple as N1 1AA or similar - your RegExp only accepts ones with exactly two initial letters, but if you are sure that doesn't matter, then the simplest re-write gives you:

Brilliant thank you! yes i am aware that some postcodes wont validate as it is but this form is only going to be used by a select set of people in a certain area all of whom have postcodes which will validate. just want to prevent them from making mistakes really!

your code does indeed work! thank you so much!

Originally Posted by omnicity

Some of the London postcodes can be as simple as N1 1AA or similar - your RegExp only accepts ones with exactly two initial letters, but if you are sure that doesn't matter, then the simplest re-write gives you: