|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
SlickEdit: Code in over 40 languages across 7 platforms. SlickEdit’s unmatched power, speed, and flexibility allows even the most accomplished developers to write better code faster. Download a free trial today! |
|
#1
|
|||
|
|||
|
Hey everyone
Now I know this isn't directly related to PHP, but some people in this forum have helped me, so now I'm giving back! Here's a neato Javascript-based validator that I think you'll like. I know it doesn't replace server-side, but it's a great first-line. Some of you may remember a post a-while back in this forum where I talked about this script some. Here it is in all it's glory. Enjoy! Feedback is welcome! http://www.peterbailey.net/jsdemo/ |
|
#2
|
|||
|
|||
|
just a problem with your script
This form assumes your from the USA. it only let me put in a 5 or 9 digit post code, even tho, my post code is 4 numbers, and i had to choose a state. just something you might wana change, like give people to option to choose a 'non american' state. but if they select a state, say new york, then it also checks the post code as 5 or 9 digits |
|
#3
|
|||
|
|||
|
I haven't tested it for myself, but it looks very nice! Thanks for sharing!
I noticed the zip-problem too.. In Norway we don't have zip codes, we have postal codes.. For example my postal code is 9512 ![]()
__________________
Best Regards, Håvard Lindset |
|
#4
|
|||
|
|||
|
Thanks for the comments.
As I mentioned on the page...this script is quite easy to add functionality to. I could easily add validation for Norway Postal codes (I'd just have to know the rules )Not sure where I can find list of all the Zip codes per state. Perhaps www.usps.gov will have that info. Remember, I made this script to be modular! So modify it how you need it! Check back, if I make updates, I'll post it here. I also plan to add validation for DECIMALS (ie decimal2|4 would require 2 digits before the decimal, and 4 digits after) Have suggestions for any other universal or semi-universal datatypes? |
|
#5
|
|||
|
|||
|
I have a feature-idea.. what about giving changing the background-color of the input field that has an error? Make it light-red or something.. (not too far from white, just give it a red tint).. the option to change color should be available too
![]() |
|
#6
|
|||
|
|||
|
thats a cool idea, that could work really nicely
|
|
#7
|
|||
|
|||
|
What you could actually do is let users specify their own postcode/state validation rules so they can customize it. then you could just use the eval() function to check it...something like this:
<script language="JavaScript"> var rule="pcode.value.length == 4 && pcode.value >= 2000"; function checkPCode(pcode) { if(eval("rule")) // OK else // Failed } </script> you get the idea...just a way to customize it ![]() |
|
#8
|
|||
|
|||
|
True, but this script is intended for web authors, not the general public of users. I really don't want to start the complexities of generating accurate regular expressions based on user input. A good idea, but not sure I'll use it here.
I'm working on the field coloring now.... OH, I did find the ZIP code data I needed to validate the Zip Code vs the State, but I'd have to pay for it... So that will be on hold for a bit...Thanks for the comments! Keep em comin! |
|
#9
|
|||
|
|||
|
Ok, I've worked on this a bit, and have the new version ready
What's new: 1) Validates decimals (thats floats to you programming geeks ) within any rules2) Validates money (US or similar currency) flexible formats 3) Provides coloring for error fields via CSS (thx for the idea Havard )Enjoy! |
|
#10
|
|||
|
|||
|
Ok, I've been toiling....
The validator now includes:
Note: If by chance you have aleady used a previous version (1.01, 1.11, 1.42) and you want to start using this version, please re-read the documentation, because some of the rules have changed and your page(s) will need updating. Last edited by beetle18 : July 24th, 2002 at 04:17 PM. |
|
#11
|
|||
|
|||
|
It seems like it's trying to validate the input when I click on the hotscripts rate submit button
|
|
#12
|
|||
|
|||
|
Woopsie....sorry about that. I think my cut & pasting got a bit over-zealous or something. Should work now.
|
|
#13
|
|||
|
|||
|
very good! i have one last suggestion, for the us states and post code, you should make a seperate file, containing variables for the postcode length and an array of the states, that means people can easily modify your code
Just an idea |
![]() |
| Viewing: Dev Articles Community Forums > Programming > General Programming Help > New validation script completed |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|