How can i validate the content of text file using javascript? For instance i have a single text file consists of :
6594567890
6594567891
6594567892
6594567893
92345678
92345679
92345680
Accordingly, I need to validate the content with certain conditions:
- if its prefix is not equal to 659 and 9 then it will be rejected.
- if its prefix is equal to 659 but the length is not equal to 10 then it will be rejected.
- if its prefix is equal to 9 but the length is not equal to 8 then it will be rejected.
Currently i have the following codes using JS:
<input type="file" name="txt_list" id="txt_list" class="inpText" size="26" />
<script>
var input_file = document.getElementById('txt_list');
input_file.onchange = function() {
var file = this.files[0];
var reader = new FileReader();
reader.onload = function(ev) {
// Show content (ev.target === reader)
alert(ev.target.result);
};
reader.readAsText(file);
};
</script>
<font color="FF0000" style="font-weight:bolder;">
<b>* Compulsory</b>
</font>
Any ideas how to do this? jsfiddle or sample codes will be highly appreciated.
Guess it is reading each line that is your concern?
ev.target.resultis a long chain of characters, it must be separated into string. It was not exactly clear to me how you would evaluate the lines, so bear over with that