473,386 Members | 1,763 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Javascript regular expression for a subject field

JnrJnr
88
Hi people, I have this regex?
Expand|Select|Wrap|Line Numbers
  1. /^[a-zA-Z0-9]+[\s]*[a-zA-Z0-9]+$/
I want the field to start with alphanumeric and allow single white spaces (or no white spaces) zero or more times and zero or more times in the sentence and then end with alphanumeric.
For example:
1. Hello John123
2. Hello John123 (with maybe 3 spaces between hello and John 123)
3. Hello John123 how are you

Help would be appreciated!
Aug 31 '11 #1

✓ answered by Dormilich

you can use parentheses (groups) to get that repetition.
Expand|Select|Wrap|Line Numbers
  1. // simplified example
  2. /^\w(?:\s?\w)+$/

6 1479
Dormilich
8,658 Expert Mod 8TB
you can use parentheses (groups) to get that repetition.
Expand|Select|Wrap|Line Numbers
  1. // simplified example
  2. /^\w(?:\s?\w)+$/
Aug 31 '11 #2
JnrJnr
88
Thanks it works for me but could you please explain how the parentheses or groups work? Im still new to regex
Aug 31 '11 #3
Dormilich
8,658 Expert Mod 8TB
well, it’s just that, a group. nothing complicated there.
Aug 31 '11 #4
JnrJnr
88
Anything desired to know that needs understanding is complicated till it is known.
Thanks again
Aug 31 '11 #5
Dormilich
8,658 Expert Mod 8TB
some things are so simple, that it’s hard to explain in a simpler way. other than that I can only refer to RegExp tutorials like this one.
Aug 31 '11 #6
JnrJnr
88
There are many tutorials and quick starts on regular expressions but I just did not know how the parentheses or groups work. A bit better link would be this http://www.regular-expressions.info/brackets.html
tanx
Aug 31 '11 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

12
by: Smash | last post by:
i have this function: ------------------------------------------------------------ function isAlfaNumeric(vnos,space) { if (space==false) { validRegExp = /^{0,}$/; } else { validRegExp =...
6
by: los | last post by:
Hi, I've created a web application using struts. I am trying to solve an issue where in one of the forms where I want to allow the values inserted to be special characters from other languages,...
5
by: John . | last post by:
I am using the Regular Expression Validator control to validate a correct email address. But, at the same time I would like to make it a required field. I tested by using just the regular...
9
by: lev | last post by:
Attempting to use javascript's regular expression methods to match a particular lab number and building which would then be copied to a pair of textfields, I found that general matching characters...
8
by: frohlinger | last post by:
Hi, I have a search textbox in my website. I validate the search string with a "white list" of allowed characters: if((/^+$/).test(theSearchWord) == false) { return; }
1
by: rporter | last post by:
I have a javascript utility and need so help with regular expressions.. Basically I have lines of data that consists of name=value pairs delimited with commas. example match=type...
1
by: sarithamartha | last post by:
Hi, I have a contact number text field,I need a regular expression which should not allow all zeros for that field.
1
by: NvrBst | last post by:
I want to use the .replace() method with the regular expression /^ %VAR % =,($|&)/. The following DOESN'T replace the "^default.aspx=,($|&)" regular expression with "":...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.