Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8732521
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T09:27:18+00:00 2026-06-13T09:27:18+00:00

How can i validate the content of text file using javascript? For instance i

  • 0

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:

  1. if its prefix is not equal to 659 and 9 then it will be rejected.
  2. if its prefix is equal to 659 but the length is not equal to 10 then it will be rejected.
  3. 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>&nbsp;&nbsp;&nbsp;&nbsp;
</font>

Any ideas how to do this? jsfiddle or sample codes will be highly appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T09:27:19+00:00Added an answer on June 13, 2026 at 9:27 am

    Guess it is reading each line that is your concern? ev.target.result is 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

    <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) {
          var str = '';
          for (var i = 0; i < ev.target.result.length; i++) {
            str += ev.target.result[i];
            if (ev.target.result[i] == "\n") { //new line
              //probably very misunderstood evaluation 
              if (((str.substr(4, 7) == '659') && (str.length != 10)) ||
                ((str.substr(4, 7) != '659') && (str.length == 9)) ||
                ((str.substr(4, 5) == '9') && (str.length != 8))) {
                alert('rejected');
              } else {
                alert('accepted');
              }
              //reset the line
              str = '';
            }
          }
        };
        reader.readAsText(file);
      };
    </script>
    <font color="FF0000" style="font-weight:bolder;">
      <b>* Compulsory</b>&nbsp;&nbsp;&nbsp;&nbsp;</font>
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can i validate content of a input box? that when a user for
I have vote and votedown tables for posts. I can validate uniqueness within the
Can I validate a form on button click without submitting the whole form using
How can i validate the text length of the element that has an attribute.
How can I validate file size from client side. It can be controlled via
How can I validate an XML file against a DTD that is stored locally
How can I validate a string using Regular Expressions to only allow alphanumeric characters
I have created dynamic pricing forms within a e-commerce site using javascript and it
I'm using jQuery's validation plugin and looking to validate many dynamically added text fields
I have a web page on which users can upload text files (but a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.