Hello Dear Javascript Experts!
I really suck at Javascript at the moment, and I could really use some
assistance...
I have an HTML form, and I'm using javascript to validate the various
entries. Now, I have most of the basic validation figured out, but
there's one input field which requires very strict validation. That
field is the "Address" field.
Besides the obvious checking of whether or not the field is empty, I
also have to make sure that it contains both letters AND numbers, so
that the Street's number isn't left out. Also, I need to make sure that
it is in fact a Street Address, and not a P.O.Box... So the script must
also check to see that the input field does not contain the words
"P.O.Box"...
To sum it up:
1. Field must contain both letters and numbers
2. Field must NOT contain the expression "P.O.Box" (or "p.o.box"..
"PO.Box"... etc)
Any code samples you can provide will be greatly appreciated!!!!!!
Thanks for your time and help!
W.Sh 5 5828
W.Sh wrote: Hello Dear Javascript Experts! I really suck at Javascript at the moment, and I could really use some assistance...
I have an HTML form, and I'm using javascript to validate the various entries. Now, I have most of the basic validation figured out, but there's one input field which requires very strict validation. That field is the "Address" field.
Besides the obvious checking of whether or not the field is empty, I also have to make sure that it contains both letters AND numbers, so that the Street's number isn't left out. Also, I need to make sure that it is in fact a Street Address, and not a P.O.Box... So the script must also check to see that the input field does not contain the words "P.O.Box"...
To sum it up: 1. Field must contain both letters and numbers 2. Field must NOT contain the expression "P.O.Box" (or "p.o.box".. "PO.Box"... etc)
Any code samples you can provide will be greatly appreciated!!!!!!
Thanks for your time and help!
W.Sh
How about regular expressions?
Say,
1) house number is a number optionally followed by letters
2) Then 1 or more spaces
3)Then street - one or more of letters followed by dot or numbers,
4) followed by 1 or more spaces :)
5) Then optionally apartment - 1 or more numbers+letters
This will allow
"29 W 4 Street"
"193A Evergreen Terrace 26A"
"1 Some Blvd. B6"
"65 4 Street"
etc.
This will deny
"Evergreen Terrace"
"25"
"W 4 Street 29"
Anyways,
1) [0-9]+[a-zA-Z]*
2) \s+
3) (([a-zA-Z]+\.)|([0-9]+))+
4) \s+
5) ([0-9a-zA-Z]+)?
So, we get:
re = /^[0-9]+[a-zA-Z]*\s+(([a-zA-Z]+\.)|([0-9]+))+\s+([0-9a-zA-Z]+)?$/
if (!re.test(address)) {
alert('invalid address');
}
That should do that :)
As for P.O.Box, it could be written in different ways, but in any case
it will be "P" followed by 0 or more spaces, optional ".", and 0 or more
spaces; then same for "O", and then "Box", so:
re = /^(P\s*\.?\s*)(O\s*.?\s*)(Box)$/
That should take care of it :)
luph
"W.Sh" <ro***********@gmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com... Hello Dear Javascript Experts! I really suck at Javascript at the moment, and I could really use some assistance...
I have an HTML form, and I'm using javascript to validate the various entries. Now, I have most of the basic validation figured out, but there's one input field which requires very strict validation. That field is the "Address" field.
Besides the obvious checking of whether or not the field is empty, I also have to make sure that it contains both letters AND numbers, so that the Street's number isn't left out. Also, I need to make sure that it is in fact a Street Address, and not a P.O.Box... So the script must also check to see that the input field does not contain the words "P.O.Box"...
To sum it up: 1. Field must contain both letters and numbers 2. Field must NOT contain the expression "P.O.Box" (or "p.o.box".. "PO.Box"... etc)
Any code samples you can provide will be greatly appreciated!!!!!!
Thanks for your time and help!
W.Sh
You might consider using "UPS U.S. Address Validation"
(from http://www.ups.com/ Online Tools) which would
"Ensure that customer-entered shipping addresses
for the United States are correct."
Post Office boxes are not valid shipping destinations.
JRS: In article <11**********************@z14g2000cwz.googlegroups .com>
, dated Sat, 31 Dec 2005 04:26:08 local, seen in
news:comp.lang.javascript, W.Sh <ro***********@gmail.com> posted : I really suck at Javascript at the moment, and I could really use some assistance...
This is an international newsgroup, so it is better not to use slang.
I have an HTML form, and I'm using javascript to validate the various entries. Now, I have most of the basic validation figured out, but there's one input field which requires very strict validation. That field is the "Address" field.
Besides the obvious checking of whether or not the field is empty, I also have to make sure that it contains both letters AND numbers, so that the Street's number isn't left out.
There are properties which do not have a street number. There are
addresses which do not include a street name.
Also, I need to make sure that it is in fact a Street Address, and not a P.O.Box... So the script must also check to see that the input field does not contain the words "P.O.Box"...
Do you know what P.O.Boxes are called in *all* national languages?
To sum it up: 1. Field must contain both letters and numbers 2. Field must NOT contain the expression "P.O.Box" (or "p.o.box".. "PO.Box"... etc)
And if Peter Osbert Box opens a shop called P.O.Box Fruiterers, then
your user may be unable to communicate with it. And it would be unwise
to live in Pobox Road.
Tell the user what sort of address you want, and let him bear the
consequences of carelessness. Don't be procrustean.
Any code samples you can provide will be greatly appreciated!!!!!!
<URL:http://www.merlyn.demon.co.uk/js-valid.htm>
<FAQENTRY> If you are only interested in code that works regionally
rather than world-wide, then it would be courteous to indicate that.
--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
On 2005-12-31, W.Sh <ro***********@gmail.com> wrote: Hello Dear Javascript Experts! I really suck at Javascript at the moment, and I could really use some assistance...
I have an HTML form, and I'm using javascript to validate the various entries. Now, I have most of the basic validation figured out, but there's one input field which requires very strict validation. That field is the "Address" field.
The best way is to make it worth their while to get the address correct.
Besides the obvious checking of whether or not the field is empty, I also have to make sure that it contains both letters AND numbers,
Not all adresses contain numbers.
There's no simple way to validate addresses.
--
Bye.
Jasen
> [John] This is an international newsgroup, so it is better not to use slang. ... ... Don't be procrustean.
why no slang, so peeps don't need a dictionary? This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: TG |
last post by:
I have a validation form that must behave differently based on the results
of a PHP validation check. I have a post command at the top of my form that
calls itself. I don't leave the form when performing the validation check on
the values that were entered into the form, I simply repost the form to
perform the PHP validation. If any of the...
|
by: Marc te Vruchte |
last post by:
Over the past years i've been in contact with the same problem a
number of times, creating a graphical user interface on complex XML
documents. Personally these solutions have never been satisfactory to
me as a developer. I am not sure if this is caused by the way i've
approached the problem or that it is the maturity of current day XML...
|
by: Mike |
last post by:
Note: My XML experience to date has (unfortunately) been limited to reading
and thinking, rather than implementation.
Anyway, I am in the process of trying to figure out the most efficient way
to validate and transform some very large (potentially over 100MB) XML
documents. This is related to another question I will post next, but for...
|
by: Czarina |
last post by:
hi guys!
here I am again, bugging you
Here is where my page stands right now:
http://www.gainesvillewebs.com/czar...h_results-2.htm
The top 2 forms are working just fine, but the bottom one, with the
check boxes, it not working
I am by NO MEANS, a Javascript expert, so please be patient!
Here is what it needs to do:
It need to check that...
|
by: Sven Neuberg |
last post by:
Hi,
I have been handed the task of updating and maintaining a web
application, written in ASP and Javascript, that takes complex
user inputs in HTML form and submits them to server-side ASP
pages for processing. The problem is, the user inputs can
become very complex, and the way this application was developed,
the inputs are all...
| |
by: Hosh |
last post by:
I have a form on a webpage and want to use JavaScript validation for the
form fields.
I have searched the web for form validation scripts and have come up with
scripts that only validate individual fields, such as an "Email Validation
Script" or a "Phone Validation Script".
Is it ok to put all these scripts on page as they are or should they...
|
by: julie.siebel |
last post by:
Hello all!
As embarrassing as it is to admit this, I've been designing db driven
websites using javascript and vbscript for about 6-7 years now, and I
am *horrible* at form validation.
To be honest I usually hire someone to do it for me, grab predone
scripts and kind of hack out the parts that I need, or just do very
minimal validation...
|
by: Chris |
last post by:
Hi,
I have a form for uploading documents and inserting the data into a mysql
db. I would like to validate the form. I have tried a couple of Javascript
form validation functions, but it appears that the data goes straight to the
processing page, rather than the javascript seeing if data is missing and
popping up an alert. I thought it...
|
by: sharsy |
last post by:
Hi guys,
I would like to setup a validation rule for a database in microsoft
access that restricts data entry so that a certain field can only be
filled in if another field has a specific answer (that is selected via
a drop down list).
Example
Field1 - options are "In" or "Out"
Field2 - options are "Join" or "Not Joining"
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |