0

I have an input box where the user can enter a string date, for example today or tomorrow. But now the next problem has arrived: 3 march or 8 january.

The input box has a dropdown menu, when the user types: "tod" => today, "jan" => "january" etc, when the user selects the dropdown item it will insert the text for them, however now the following question:

3 januari, or 03 januari, or 3 januari, as you can see it requires some regex, to check whether the first part was numeric? and then a space comes (for x amount of times since we cannot rely on users :P) and then the name of the month?

How can I do this?

Thanks for help already.

1
  • can you give an example of what you have already? perhaps using jsfiddle.net Commented Dec 28, 2011 at 1:17

2 Answers 2

1
"13 august".match( /\s*(\d+)\s+(january|february|march|april|may|june|july|august|september|october|november|december)/ ); 

After this you can do

var day = parseInt( RegExp.$1, 10 ); var month = [ 'january', 'february', 'march', 'april', 'may', 'june', 'july', 'august', 'september', 'october', 'november', 'december'].indexOf( RegExp.$2.toLowerCase() ) + 1; alert( month + "/" + day ); 

Look at this jsfiddle.

Sign up to request clarification or add additional context in comments.

Comments

0

Just the regex would be something like this

[0-9]{1,2}\s\w* 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.