Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Regular Expression for Address field...

Posted on 2006-07-10
7
Medium Priority
?
684 Views
Last Modified: 2006-11-18
I need a regular expression to validate my address field, the condns are...
1. Address field must not start with and empty space (also should not be empty)
2. Address field can contain any alpha numeric characters (Only Capital Letters) and any kind of symbols and it should start with one of the Alphanumeric charcters
3. It can contain any number of spaces in between the words (just like a sentence...)
4. It shud not exceed 200 char.

Thank You,
Steve
0
Comment
Question by:steve_mick972
  • 3
  • 2
  • 2
7 Comments
 
LVL 10

Expert Comment

by:0h4crying0utloud
ID: 17077372

This should work:

<body>

  <input type="text" onblur="checkIt(this.value)">

</body>

<script>

function checkIt(testStr) {
  if( !(testStr.length < 200 && testStr.match(/^[a-zA-Z0-9]/))) {
        alert(" not OK");
      }
      else {
        alert("OK");
      }
}

</script>
0
 
LVL 10

Expert Comment

by:0h4crying0utloud
ID: 17077390
Whoops I missed the caps condition...

ths is a user friendly way of doing it:

<body>

  <input type="text" onblur="this.value=this.value.toUpperCase(); checkIt(this.value);">

</body>

<script>

function checkIt(testStr) {
  if( !(testStr.length < 200 && testStr.match(/^[a-zA-Z0-9]/))) {
        alert(" not OK");
      }
      else {
        alert("OK");
      }
}

</script>
0
 
LVL 1

Author Comment

by:steve_mick972
ID: 17077431
It is not working...
Its not matching any proper address...
I tried:
123 ADFOME DSDFD
DFDSFEG SDFSDLKL & SDFJDLSF
SDFGF%SDF 34343 & SDFDSF
the above strings should result in success...

Stings I dont want:
 DFDSFEFS SDFDSF (space as first char)
""(empty string)
etc.

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 63

Expert Comment

by:Zvonko
ID: 17077671
Here my proposal:



<input type=text name="Address" maxLength="200" onBlur="checkAddr(this)">
<script>
function checkAddr(theField){
  if(!theField.value.match(/^[A-Z0-9][A-Z0-9\%\&\.\ ]+$/)){
    alert("Enter Address.");
    theField.select();
    theField.focus();
    return false;
  }
}
</script>


0
 
LVL 1

Author Comment

by:steve_mick972
ID: 17077726
OK, I donno what is happening, Im testing that regular expression using online tool located at:
http://www.regular-expressions.info/javascriptexample.html
but for some reason Zvonko's test string is also does not result valid addresses...

Could you please tell me whether am I doing anything wroing or I am not supposed to check this reg. expr. there???

Thank You,
Steve
0
 
LVL 63

Expert Comment

by:Zvonko
ID: 17079675
Do you remove the first and the last forward slash?
0
 
LVL 63

Accepted Solution

by:
Zvonko earned 1500 total points
ID: 17079705
This is what you put into "Regular Expression Tester" form's Regexp field:      
 
^[A-Z0-9][A-Z0-9\%\&\.\ ]+$


0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

972 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question