Saturday, December 10, 2011

Check a chromosome region with jQuery validator

A chromosome region is the part of a chromosome defined either by anatomical details, especially by banding, or by its linkage groups, and divided in bands and subbands. In other words, these regions have been defined to talk about the location of a gene. The regions p and q are respectivelly used for the short arm and the long arm of the chromosome.

Here are some examples of chromosomal regions: 13q14, 1p12, 1p12.3
1p12.3 means on the short arm (p) of the chromosome 1, region 1, band 2, subband 3.

Note: I limit myself here to a simplified notation, as the complete notation would take into account the possible presence of a + or - sign after the letter p or q (gain or loss of chromosome) and translocation.

The jQuery validation plugin can be used to validate any kind of form field, and used with a regular expression, it can check against any text content.
In the following example, we define a chromosome region as a string of one or two digits, followed by the letter p or q and two more digits, eventually followed by a dot and one or two more digits.
jQuery.validator.addMethod("chromosomalRegionValidator", function(value, element) {
    return /^((\d{1,2})(p|q)(\d\d)|(\d{1,2})(p|q)(\d\d)\.\d{1,2})$/i.test(value);
}, 'Please enter a valid chromosome region (e.g.: <i>9p21</i>, <i>13q14</i>, <i>5p13.1</i>...)');


Vérifier une région chromosomique avec jQuery validator (in French)
Verificar uma região cromossômica com o validator jQuery (in Portuguese)
Verificar una región cromosómica con el validator jQuery (in Spanish)

No comments:

Post a Comment