Solved

Regular Expression for Address field...

Posted on 2006-07-10
7
662 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
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…

707 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now