javascript - validate text box input (for fasta format) before submission -
i want validate text box input on html page whether in fasta
format or not , if contains 1 sequence before submission of data.
i know php , little idea javascript. don't think possible php.
in order validate using javascript, can use following function:
/* * validates (true/false) single fasta sequence string * param fasta string containing putative single fasta sequence * returns boolean true if string contains single fasta sequence, false * otherwise */ function validatefasta(fasta) { if (!fasta) { // check there first of return false; } // remove trailing spaces fasta = fasta.trim(); // split on newlines... var lines = fasta.split('\n'); // check header if (fasta[0] == '>') { // remove 1 line, starting @ first position lines.splice(0, 1); } // join array single string without newlines , // trailing or leading spaces fasta = lines.join('').trim(); if (!fasta) { // empty whatever collected ? re-check not efficient return false; } // note empty string caught above // allow selenocysteine (u) return /^[acdefghiklmnpqrstuvwy\s]+$/i.test(fasta); }
source: http://www.blopig.com/blog/2013/03/a-javascript-function-to-validate-fasta-sequences/
note, however, should perform same check on server side php
. languages similar, , php provides need.
Comments
Post a Comment