Solved

Regular Expression for Address field...

Posted on 2006-07-10
7
671 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 500 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

Independent Software Vendors: 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!

Question has a verified solution.

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

I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
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…

763 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