Hi All,
I'm creating a form that it will parse a valid address in the address1 field from an address library to make sure this is a valid address. Here is the problem: The address is followed by the city and zip code inside of my address1 field. It looks like this:
Address 1: 10142 sterling ter. Rockville, 20850
I need to clean the 2 tabs between the data of the address1 and Rockville, 20850 using javascript. I'll appreciate if you could help me.
8 1932 gits 5,390
Expert Mod 4TB
hi ...
tabs? could you give an example of the output you need?
kind regards
Sorry, looks like the space beteween the address1 and Rockville doesn't show in the first message.
It's like this: 10142 sterling ter "space" " space" Rockille 20850.
space is as big as a tab.
Sorry, looks like the space beteween the address1 and Rockville doesn't show in the first message.
It's like this: 10142 sterling ter "space" " space" Rockille 20850.
space is as big as a tab.
The output I need is: 10142 sterling ter.
gits 5,390
Expert Mod 4TB
hi ... :)
have a look at the following example: - var s = '10142 sterling ter. Rockville, 20850';
-
-
s = s.match(/([^ \t]+)/g);
-
-
s = s.splice(0, 3).join(' ');
-
-
alert(s);
-
we may use a regExp here to match the words only and no spaces and tabs first. next we 're-join' the first 3 elements of the result-array that we got before.
kind regards
Hi gits,
Thank you so much for your suggestion. Please take a look at the whole javascript below: - <script>
-
-
var url1="http://zip4.usps.com/zip4/zcl_0_results.jsp?visited=1&pagenumber=0&firmname=&address2=";
-
-
// 2 Broadway
-
-
var url2="&address1=&city="; //NEW YORK
-
-
var url3="&state=";//NY
-
-
var url4="&urbanization=&zip5=";
-
-
-
-
function getAddress( address1, city, state)
-
-
{
-
-
if(address1=="" || city=="" || state =="")
-
-
{
-
-
alert('fill in all fields.');
-
-
-
return;
-
-
}
-
-
var fullurl=url1+address1+url2+city+url3+state+url4;
-
-
var x=createXMLHttp();
-
-
x.open("GET",fullurl, false);
-
-
x.Send(null);
-
-
var res=x.responseText;
-
-
try{
-
-
// strip off everything before where the result starts
-
-
var startpos = res.indexOf("<td headers=\"full\"")+124;
-
-
res=res.substring(startpos)
-
-
if(res.toUpperCase().indexOf("<HTML")>0)
-
-
{
-
-
alert('Address is not valid.');
-
-
return;
-
-
}
-
-
// strip off everything after the result
-
-
var endpos=res.indexOf("</td>")-10;
-
-
res=res.substring(0,endpos);
-
-
//clean up line breaks
-
-
res=res.replace("<br />","");
-
-
res=res.replace("<br/>","");
-
-
res=res.toUpperCase();
-
-
// clean off HTML Spaces
-
-
res=res.replace("&NBSP;", " ");
-
-
res=res.replace("&NBSP;", " ");
-
-
res=res.replace("&NBSP;", " ");
-
-
res=res.replace("&NBSP;", " ");
-
-
<!--- res=res.replace("res.match("/t")[a-zA-Z]*", " "); --->
-
-
-
var ad = 'address1';
-
-
ad = ad.match(/([^ \t]+)/g);
-
-
ad = ad.splice(0, 3).join(' ');
-
-
<!--- alert(ad); --->
-
-
-
document.getElementById('address1').value=res;
-
-
}
-
-
catch(e)
-
-
{
-
-
alert('Address is not valid.');
-
-
}
-
-
}
-
It get the full url as address and then it check the validity of the address, if not valid, it will replace the valid address in the address1 field. but the city and zipcode are added to the address and I don't want them. As you see I included your suggestion in the javascript as well. It clean the city and zip but the address validation doesn't work anymore. do you know why? Thank you so much for your support.
gits 5,390
Expert Mod 4TB
actually the var ad is a string 'address1' and so the code will do nothing and you assign the res to the textfields value without stripping the tabs and spaces? ad should be res i think :)
Doa... Thank you so much. Here is the changes I made.
<!---var res = 'address1'; --->
res = res.match(/([^ \t]+)/g);
res = res.splice(0, 3).join(' ');
<!--- alert(ad); --->
document.getElementById('address1').value=res;
I think I got it.
gits 5,390
Expert Mod 4TB
cool ... glad to hear you got it working ... post in the forum anytime you have more questions :)
kind regards
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Dynamo |
last post by:
Hi
The following script was taken from John Coggeshall's (PHP consultant) in his
article on Zends site at http://www.zend.com/zend/spotlight/ev12apr.php
// Get the email address to validate...
|
by: Angel |
last post by:
Hi there,
I need help pls..I'm using c# on a webform and I have this regex validation
for email addresses: ValidationExpression
="\w+(\w+)*@\w+(\w+)*\.\w+(\w+)* "
I'm having isssues when submit...
|
by: gotFun |
last post by:
I am unable to set focus to an IP address control residing on a Property Page, following validation of the IP when the user hits the 'Finish' button on the Property Sheet.
I've unsuccessfully...
|
by: Wm. Scott Miller |
last post by:
Hello all:
I'd like some advice on the best way to validate and confirm an e-mail
address entered during a registration process. What we are thinking of is
something like the following:
1. ...
|
by: Mika M |
last post by:
Simple question: Does Framework (1.1) contain any routine to check entered
email-address is valid ?
It's quite easy to make own code for that purpose, but why to do if
Framework (1.1) contain...
|
by: cemcat |
last post by:
Hello,
We have an ASP.NET 2.0 (C#) web form that contains a textbox for users to
enter multiple e-mail addresses separated by semicolons. We need to
validate that each individual e-mail address...
|
by: prabhuram.k |
last post by:
Can anybody know how to validate IPV4 and IPV6 address in C++
|
by: Fur Data |
last post by:
Hello,
We are developing and providing the virtual market with an address
validation add-on for 18 countries.
A realtime prototype website can be visit at www.address-validation.com
Via a...
|
by: Keith G Hicks |
last post by:
I'm using the following code to send out email messages to a list of people
in a database. My problem is that if I'm sending to 100 people and the 40th
address is bad, it crashes on that one and...
|
by: John Wright |
last post by:
I want to validate an email address against our Exchange server. Anyone
have code or point me in the right direction?
John
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
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,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |