/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] Javascript regular expression help

Hi,

I have an input field that i want to validate and capture numbers with a wefined format:

Example: (123d{6})+

i want to be able to read those numbers ignoring spaces between them and the use of some separator between them

Example string:

[COLOR=”#00FF00″][B]123456789[/B][/COLOR] ; [COLOR=”#FF0000″][B]123456789[/B][/COLOR]9 , dddd [COLOR=”#FF0000″][B]123456789[/B][/COLOR]00000 xxxxxx [COLOR=”#FF0000″][B]123456789[/B][/COLOR]101112 1234567890 “

I want to be validate and get the valid numbers(highlithed in green) but i’m capturing some wrong matches – partial match (in red)

where is the example:

[url]http://scriptular.com/#(123%5Cd%7B6%7D)%2B%7C%7C%7C%7Cigm%7C%7C%7C%7C%5B%22%20%20123456789%20%3B%201234567899%20%20%20%2C%20%20%20%20dddd%2012345678900000%20%20xxxxxx%20%20%20123456789101112%201234567890%20%20%20%20%20%22%5D[/url]

Thanks for any help,

Manuel

to post a comment
JavaScript

5 Comments(s)

Copy linkTweet thisAlerts:
@Sup3rkirbyNov 24.2014 — I'm not entirely sure if I understand what you want. Could you potentially post all of the 'valid' matches you want to see so that I can understand what you are trying to achieve?

My first guess would be something like: [B]/d+/g[/B]

But I feel like I don't have enough to go on. That regular expression matches each full set of numbers in your example, but of course I'm not really sure if that's what you are trying to do.
Copy linkTweet thisAlerts:
@toucomxonoauthorNov 24.2014 — Thank you Sup3rkirby,

The valid match that i want (in the above example input string) is only the first "123456789". I want to parse and capture the numbers with the specified format "123d{6}", so 123456789 is valid, and 1234567890 is not valid.

More examples:

123456789 - valid

1234567890 - invalid

aaa - invalid

999999999 - invalid

123aaaaaa - invalid

i want to apply a regular expression and then iterate through the valid elements.

Best regards.
Copy linkTweet thisAlerts:
@Sup3rkirbyNov 24.2014 — As I mentioned in my first reply, [B]/d+/g[/B] was merely my first guess at what you wanted and was intended to simply match the full groupings of numbers (rather than partial groupings) because I wasn't quite sure what matches you wanted.

Now I do think I have a better understanding and so my suggestion is: [B]/123d{6}b/g[/B]

All of this is a bit out of context though. I can't say this is the best way to go about what you want, but writing a better regular expression would require a better understanding of the actual data you will have and the actual matches you want to see. [U]This regular expression matches [B][I]any 9 digit number that begins with 123[/I][/B][/U]. It fits the examples you gave but again, this is kind of out of context so I can't guarantee that this is what you will need for whatever you are trying to do.
Copy linkTweet thisAlerts:
@toucomxonoauthorNov 24.2014 — That suits my needs! ?


Thank you very much!
×

Success!

Help @toucomxono spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...