Jump to content

RegExp with [space] allowed?


monkeytooth

Recommended Posts

I am tempting to filter my form inputs with jquery. I am currently playing with RegExp. But I am noticing I am limiting myself a bit. Some of the fields like the Address Fields for example need the ability to have a space between things. example: "123 MyStreet Rd."

 

However from my poking around I can't come across a regexp format that will allow things like . and [space], nor can i think of one on my own. Needless to say I am a bit stuck. Is anyone able to help me on this?

 

RegExp('[^a-zA-Z]+', 'g');
val = val.replace(pattern, '');

 

var pattern = new RegExp('[^0-9a-zA-Z]+', 'g');
val = val.replace(pattern, '');

 

Above are the 2 things I am using right now. One to allow strickly alphabetic input and one to allow a combination of alpha and numeric. But how to add a space or a period or a comma in the expression I don't know. I am lost, any help would cool.

 

Link to comment
Share on other sites

http://www.lousyllama.com/blog/jquery-autotab-11-beta-ready-testing#comment-288

 

is the script I am working with. I am attempting to use its "Custom" filter while attempting to build my own regexp to verify if a street address is good or not

 

I have spent several hours prior to this original post and after trying various ways of putting a regexp together for this and have failed each time. I am no good with this regexp stuff. Can anybody help me with this, I can't move on in my project til i solve this cause I have OCD, and its beyond me.

 

I just want a means to handle "123 Some St." that can also accept the following with or without the dot, with or without a hyphen, with or without a #, with or without a comma, with a space.

 

anyone able to help me out here? please? I can't be stuck on this for days and days. This is most likely something simple to anyone who knows regexp better than I.

Link to comment
Share on other sites

In simple terms you can extend the character class ([…]) with the extra characters that you want to allow, for example [^0-9a-zA-Z.#, -]+

 

If you need stricter checking (the above would allow #.......,,,----### as a valid address) do let us know more precisely what you're willing to allow/deny.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.