Solved

Regular Expression for Address field...

Posted on 2006-07-10
7
675 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
javascript form - error when hitting enter 3 46
Building JSON/JQuery Results Display 11 53
XML loaded in a form with dropdown 6 54
javascript duplicates 9 25
This article shows how to create and access 2-dimensional arrays in JavaScript.  It includes a tutorial in case you are just trying to "get your head wrapped around" the concept and we'll also look at some useful tips for more advanced programmers. …
This article discusses how to create an extensible mechanism for linked drop downs.
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

734 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