Click here to Skip to main content
15,890,399 members
Home / Discussions / JavaScript
   

JavaScript

 
GeneralRe: regex help Pin
thoiness21-Apr-15 11:21
thoiness21-Apr-15 11:21 
GeneralRe: regex help Pin
Wombaticus21-Apr-15 11:28
Wombaticus21-Apr-15 11:28 
AnswerRe: regex help Pin
Kornfeld Eliyahu Peter18-Apr-15 21:36
professionalKornfeld Eliyahu Peter18-Apr-15 21:36 
GeneralRe: regex help Pin
Wombaticus18-Apr-15 22:45
Wombaticus18-Apr-15 22:45 
GeneralRe: regex help Pin
Kornfeld Eliyahu Peter18-Apr-15 22:51
professionalKornfeld Eliyahu Peter18-Apr-15 22:51 
GeneralRe: regex help Pin
Wombaticus18-Apr-15 23:01
Wombaticus18-Apr-15 23:01 
GeneralRe: regex help Pin
Kornfeld Eliyahu Peter18-Apr-15 23:07
professionalKornfeld Eliyahu Peter18-Apr-15 23:07 
AnswerRe: regex help Pin
Richard Deeming20-Apr-15 3:23
mveRichard Deeming20-Apr-15 3:23 
Although you've got a solution, I can't obviously see that anyone's given you an explanation why the commented out line doesn't work. Smile | :)
JavaScript
var re = new RegExp("^([1-9]|1[0-2]|0[1-9])/(\d{4})$");

In Javascript strings[^], the backslash (\) is used to escape the following character. As a result, your pattern actually comes out as:
^([1-9]|1[0-2]|0[1-9])/(d{4})$

That's looking for the literal character "d", not the digits character class "\d".

You can solve it by either escaping the backslash within the string:
JavaScript
var re = new RegExp("^([1-9]|1[0-2]|0[1-9])/(\\d{4})$");

or using a regular expression literal:
JavaScript
var re = /^([1-9]|1[0-2]|0[1-9])\/(\d{4})$/;

NB: For a regular expression literal you have to escape the forward-slash (/) character, since that's also used to terminate the literal.



"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer


GeneralRe: regex help Pin
Wombaticus20-Apr-15 3:28
Wombaticus20-Apr-15 3:28 
QuestionTemplating systems, do we need them ? Pin
Mark C Lester17-Apr-15 22:15
Mark C Lester17-Apr-15 22:15 
Questionhow we can change colors in table cells with time duration Pin
Member 1132187815-Apr-15 20:28
Member 1132187815-Apr-15 20:28 
QuestionUsing server side includes to retrieve Javascript Pin
Mark C Lester13-Apr-15 2:11
Mark C Lester13-Apr-15 2:11 
AnswerRe: Using server side includes to retrieve Javascript Pin
Mark C Lester14-Apr-15 0:58
Mark C Lester14-Apr-15 0:58 
AnswerRe: Using server side includes to retrieve Javascript Pin
Leng Vang2-Jul-15 9:58
Leng Vang2-Jul-15 9:58 
QuestionUnable to access popup forum Pin
Sudhir Varma10-Apr-15 19:53
Sudhir Varma10-Apr-15 19:53 
SuggestionRe: Unable to access popup forum Pin
ZurdoDev13-Apr-15 4:20
professionalZurdoDev13-Apr-15 4:20 
QuestionPassing parameter from javascript/AJAX to ASP.NET app Pin
AnkurBhardwaj7-Apr-15 23:29
AnkurBhardwaj7-Apr-15 23:29 
AnswerRe: Passing parameter from javascript/AJAX to ASP.NET app Pin
faizulhaque10-Apr-15 2:41
faizulhaque10-Apr-15 2:41 
Questionhow can we get a selected row value in grid using javascript Pin
Member 113218787-Apr-15 21:23
Member 113218787-Apr-15 21:23 
AnswerRe: how can we get a selected row value in grid using javascript Pin
RajeeshMenoth8-Apr-15 19:35
professionalRajeeshMenoth8-Apr-15 19:35 
Questionjavascript Pin
Member 113218787-Apr-15 19:50
Member 113218787-Apr-15 19:50 
AnswerRe: javascript Pin
Afzaal Ahmad Zeeshan7-Apr-15 22:38
professionalAfzaal Ahmad Zeeshan7-Apr-15 22:38 
AnswerRe: javascript Pin
Anurag Gandhi31-May-15 2:26
professionalAnurag Gandhi31-May-15 2:26 
QuestionHow to multiply layer colors in photoshop with javascript? Pin
Member 1155424825-Mar-15 1:53
Member 1155424825-Mar-15 1:53 
QuestionRefresh only particular Div without reloading whole page Pin
Member 1154215920-Mar-15 8:00
Member 1154215920-Mar-15 8:00 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.