Issue with masked input in jQuery datepicker in french language - jquery-ui-datepicker

I am using jquery datepicker which supports localization and masked input. My problem is specifically with french language and format 'd M, yy'. In french, short month names are as below:
['Jan','Fév','Mar','Avr','Mai','Jun','Jul','Aoû','Sep','Oct','Nov','Déc'].
I am not able to type accent characters for months Feb, Aug and Dec. All dates with other months can be typed properly. Even if I copy "Déc", I am not able to enter this value. Does anyone know how this can be solved?
Sample code in below link:
http://jsfiddle.net/shahrashmi/mf19c2wr/

Finally I found out the root cause. This is mainly due to month format and masking for specific language. Month format is where user enters short month names, so masking used was 'aaa' for month. But this mask only allows [A-Za-z] character set. As french has accent characters, those were not supported in the mask. So, I created new mask definition "[A-Za-z\u00C0-\u024F]" and used it for month masking.
The answer is updated in the same fiddle.

Related

Regular expression to expand to sentence

I'm trying to extract regions around keywords from longer passages of text. They should include complete sentences, based on the following conditions:
n=250 Charactars before / after keyword should be included if existing (the keyword can be closer then this to the start / end of the text)
from there it should expand further to include the complete sentence (let's assume here we can define sentence borders with ".?! or :" knowing it's not completely accurate)
I already achieved the expanding to the end of the last sentence, but not to start of the first in the following example, where vitamin is the keyword and the italic is captured by the regex. However, it should capture from "An extra 24 hours..."
Apparently I don't get the corresponding group up front, neither using lazy nor using lookbehind.
((.{0,250}(vitamin)\b.{0,250})(.+?(\.|\!|\?|\:))?)/ig
Well, this year you’re getting an extra day to get ahead on your taxes or (finally) clean out the garage. (Hey, we’re not trying to tell you what do but you might as well be productive.) February 29 is back on the calendar this year because it’s a leap year. Whether you love or loathe the extra winter day, you’re probably wondering why it happens in the first place. An extra 24 hours — or day — is built into the calen dar every four years to ensure it aligns with the Earth’s movement around the sun. There’s 365 days in a calendar year, but it actually takes longer for the Earth’s annual journey — about 365.2421 days — around the star that gives us light, life and vitamin D. The difference may seem like no big deal to us, but over time, it adds up. “To ensure consistency with the true astronomical year, it is necessary to periodically add in an extra day to make up the lost time and get the calendar back in sync with the heavens,” according the history. com.
Acknowledgement of the need for a leap year happened around the time of Julius Caesar. In 46 B.C., Caesar enlisted the help of astronomer Sosigenes to update the calendar so that it had 12 months and 365 days, including a leap year every four years.,
You can try something like this:
(([.?!:][^.?!:]*.{250}\bvitamin\b.{250})[^.?!:]*[.?!:])
It works by consuming 250 characters of text before and after the keyword "vitamin". From that point it finds the first punctuation point (.?!:) before/after the 250 characters of text.
Here's a sample of it in action.
You can you use extra parentheses () to strategically group what exact output you want. For example, the above answer includes the ending period from the preceding sentence in the output. So you could use
(([.?!:]([^.?!:]*.{250}\bvitamin\b.{250})[^.?!:]*[.?!:]))
and use group 3 from the result set which doesn't have this ending period.
I do not see how the specification in the question can be matched by a regex. It boils down to the following logic problem:
to match as many characters as possible but no more than 250 before/after the keyword, .{0,250} needs to be greedy and can neither be lazy .{0,250}? nor possessive .{0,250}+
if this part is greedy, you will miss the occurrences of the keyword that start before the .{0,250} part is matched.
The same logic applies to my understanding to the 'match back to the start of the sentnence as well.
I played around with the following more or less meaningful regex:
[.?!:]?([^.?!:]*?(.{0,250}\byear\b.{0,250})[^.?!:]*[.?!:]?) misses first 'year'
[.?!:]?([^.?!:]*?(.{0,250}?\byear\b.{0,250})[^.?!:]*[.?!:]?) gets the first 'year' but fails on others.
I suggest you write your on extraction logic in a function, eihter using regex or not, to achieve the extraction you want.
You could for example find the index of the start of the keyword \bkeyword\b and the full stops (\.[^\d]|[.?!:]$) and then with this information extract the part of the text you want.

Regex for dates format

I am working under the Web Application based on ASP.NET MVC 5 and I have a great problem in my project with the field which gives the user the ability to choose format for showing Dates in the application.
The goal is to make RegularExpressionAttribute with the regex for validation date formats inputted by user.
Acceptable formats must be:
m/d/y,
m-d-y,
m:d:y,
d/m/y,
d-m-y,
d:m:y,
y/m/d,
y-m-d,
y:m:d
and the length of the date symbols may be as 'y' so far 'yyyy'. And they can be upper case.
So after hard-coding I've made the acceptable one:
((([mM]{1,4})([\/]{1})([dD]{1,4})([\/]{1})([yY]{1,4}))|(([mM]{1,4})([\-]{1})([dD]{1,4})([\-]{1})([yY]{1,4}))|(([mM]{1,4})([\:]{1})([dD]{1,4})([\:]{1})([yY]{1,4})))|((([dD]{1,4})([\/]{1})([mM]{1,4})([\/]{1})([yY]{1,4}))|(([dD]{1,4})([\-]{1})([mM]{1,4})([\-]{1})([yY]{1,4}))|(([dD]{1,4})([\:]{1})([mM]{1,4})([\:]{1})([yY]{1,4})))|((([yY]{1,4})([\/]{1})([mM]{1,4})([\/]{1})([dD]{1,4}))|(([yY]{1,4})([\-]{1})([mM]{1,4})([\-]{1})([dD]{1,4}))|(([yY]{1,4})([\:]{1})([mM]{1,4})([\:]{1})([dD]{1,4})))|((([yY]{1,4})([\/]{1})([dD]{1,4})([\/]{1})([mM]{1,4}))|(([yY]{1,4})([\-]{1})([dD]{1,4})([\-]{1})([mM]{1,4}))|(([yY]{1,4})([\:]{1})([dD]{1,4})([\:]{1})([mM]{1,4})))
This one works... But according to my scarce regex knowledge and experience I hope to get some help and better example for resolving this puzzle.
Thanks.
You have to generalize a bit.
m{1,4}([:/-])d{1,4}\1y{1,4}|d{1,4}([:/-])m{1,4}\2y{1,4}|y{1,4}([:/-])m{1,4}\3d{1,4}
Explanation:
instead of e.g. [mM] use m and set option for case insensitive match
([:/-]) all allowed delimiters as group
\1...\3 back reference to the delimiter group 1...3

Regex - "captured group equals" in a condition

I am writing a regex to capture various date formats. To keep it short and flexible, I wanted to pack all the possible combinations of months, days and years into separate groups. Let`s assume I have two dates like this:
01.01. - 31.12.2013
jan - dec 2013
Now, what I want to achieve is to write a regex that would capture both dates like the above ones. that's easy. but I also want to exclude dates like e.g. those:
01.01. - 31 dec 2013
In other words, whenever the months are mixed, I don't want those dates. Also, if the first date doesn't have a day, I don't want that day to be captured in the second one either.
I wanted to build a conditional which captures only the second date's appropriate fields, based on what is found in the first one (so, e.g. if the first date has an alpha month, look only for an alpha month in the second one, ignore numeric). My regex looks like this:
(?<firstDay>0[1-9]|[12][0-9]|3[01]|[1-9])[-/\s\.](?<firstMonth>0[1-9]|1[012]|[\p{L}]{3,}|[1-9])\s*[-\s/\.]*\s*(?<secondDay>0[1-9]|[12][0-9]|3[01]|[1-9])[-\s/.]*(?<secondMonth>((?<firstMonth>)(?<=0[1-9]|1[012]|[1-9]))(0[1-9]|1[012]|[1-9])|[\p{L}]{3,})[-\s/\.]*(?<year>(19|20)\d\d|[012][0-9]$)
This is all background, but what my question is, is it possible to check what the captured group is equal to and build a capturing condition based on that? I found some similar topic on Stack Overflow (can't find it now to referenec, unfortunately), but when I implement it, it stops capturing some proper dates (e.g. 01.01. - 31.12.2013). This is that part:
(?<secondMonth>((?<firstMonth>)(?<=0[1-9]|1[012]|[1-9]))(0[1-9]|1[012]|[1-9])|[\p{L}]{3,})

Regex to match date of type: ddmmyyyy

I'm trying to match dates of type:ddmmyyyy
, like: 04072001
So far I have this:
^(?:(?:31(?:0?[13578]|1[02]))\1|(?:(?:29|30)(?:0?[1,3-9]|1[0-2])\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:290?2\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:0?[1-9]|1\d|2[0-8])(?:(?:0?[1-9])|(?:1[0-2]))\4(?:(?:1[6-9]|[2-9]\d)?\d{2})$
which is almost the same as here but without the delimiters( (\/|-|\.) )
You could use something more simple like this:
^(0[1-9]|[1-2][0-9]|31(?!(?:0[2469]|11))|30(?!02))(0[1-9]|1[0-2])([12]\d{3})$
It captures the day, month, year, and validates everything except for whether Feb. 29 is actually a leap year. (To do that, I'd just perform the math on the captured year/date afterwards rather than trying to write it into the expression).
Working example: http://regex101.com/r/dH8mG3
Explained:
- Capture the day: 01-29
- OR 31, if not succeeded by 02, 04, 06, 09, or 11
- OR 30, if not succeeded by 02
- Capture the month: 01-12
- Capture the year: 1000-2999 (you could narrow this down
by using number ranges like
(1[8-9]\d{2}|20\d{2}) == 1800-2099
A regular expression is not the best tool for this job.
If at all possible, just match ^\d{8}$ (or ^\d\d\d\d\d\d\d\d$ if your regexp engine doesn't support the {8} syntax) and then programmatically check that the date is valid.
In a bit more detail:
Match ^(\d\d)(\d\d)(\d\d\d\d)$ (adjust syntax as needed).
Extract the three matching groups and programmatically check that they constitute a valid date.
The latter requires (a) knowing the number of days in each month, and (b) knowing which years are leap years (which depends on which calendar you're using; Gregorian is the obvious choice, but think about years before it was introduced).
The resulting code will be much easier to read and maintain.
(Also, if you have any control over the format, consider using YYYYMMDD rather than DDMMYYYY; it sorts correctly and it's one of the formats specified by the ISO 8601 standard.)
Do not validate dates using only RegEx. Your language probably has a built in date object with its own methods and such which you can use in conjunction with your input whose format you've validated with RegEx.

RegEx Date Validation for M/D/YYYY and MM/DD/YYYY (InfoPath)

I'm looking for some RegEx for a custom pattern validation for a date field in InfoPath 2010. The accepted date format is m/d/yyyy or mm/dd/yyyy.
Attempt 1: (\d{1,2})/(\d{1,2})/(\d{4})
Attempt 2: (0?[1-9]|[12][0-9]|3[01])/(0?[1-9]|1[012])/((19|20)\d\d)
Had better luck with attempt 1, and not much at all with attempt 2.
I've been having some date and time validation issues with InfoPath 2010 and regex pattern matching can be a useful approach. A basic regex for validating m/d/yyyy (without catering for the specific days in a month and allowing for '0' prefix to month or day) would be something like the following (untested):
(0?[1-9]|1[012])\/(0?[1-9]|[12][0-9]|3[01])\/\d{4}
For something more sophisticated you could have a look at this SO answer.
However, in InfoPath the format of the date displayed can be completely different to the internal format and it is this internal format that your regex needs to match. If you drop a calculated field on your form and set it to the date field you want to validate you will see something like:
2013-05-08T12:13:14
So a regular expression (again ignoring specific days per month) required to validate the date component of this is:
\d{4}-(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01])
But this won't match against the example date because it doesn't account for the time portion following the "T". So the trick is to use an expression to perform the match against the date substring only, e.g. in my case the following works:
not(xdUtil:Match(substring-before(dfs:dataFields/my:SharePointListItem_RW/my:DateCreated, "T"), "\d{4}-(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01])"))
I tried the following and it worked:
\d{4}-\d{1,2}-\d{1,2}
As David pointed out the internal format might be different than the one displayed because when I tried \d\d/\d\d/\d\d\d\d it didn't work even though it caters to the displayed format of the date.
I had the same problem.
I used a rule on the date field to set another hidden text field to
string(datefield).
That always came out YYYY-MM-DD which is not too hard to create a regex against. I used this one.
((19|20)\d\d)-(0?[1-9]|1[012])-(0?[1-9]|[12][0-9]|3[01])
Remember that it has to be an XML Regex which has some restrictions.
Then I set another rule on the hidden field to set a Boolean IsDateValid.