»
EnglishFrenchVietnamese

Print - ICD-10 Code Format Validation - JavaScriptBank.com

Full version: jsB@nk » Form » Validation » ICD-10 Code Format Validation
URL: https://www.javascriptbank.com/icd-10-code-format-validation.html

ICD-10 Code Format Validation © JavaScriptBank.comThis JavaScript validates the entered value to see if it conforms to the ICD-10 format. (It does not check whether the code exists in the ICD-10 WHO library.)

Full version: jsB@nk » Form » Validation » ICD-10 Code Format Validation
URL: https://www.javascriptbank.com/icd-10-code-format-validation.html



JavaScript
<script type=text/javascript>// Created by: Andreas Hörl :: http://www.no-x.netfunction checkICD() {  var sText = document.myForm.ICDfield.value;  var ValidChars = "0123456789.";  var ValidCharsABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";  var ValidCharsPoint = ".";  var IsICD=true;  var Char;  var lengthICD = sText.length; if ( (lengthICD < 3) || (lengthICD == 4) || (lengthICD > 6) ) {  if (lengthICD != 0) {   IsICD = false; }}   for (i = 0; i < sText.length && IsICD == true; i++) {    Char = sText.charAt(i);       if (i == 0) {       if (ValidCharsABC.indexOf(Char) == -1) {          IsICD = false; }      }      if (i == 1 || i == 2) {       if (ValidChars.indexOf(Char) == -1) {         IsICD = false;        }      }      if (i == 3) {       if (ValidCharsPoint.indexOf(Char) == -1) {          IsICD = false;        }      }      if (i == 4) {       if (ValidChars.indexOf(Char) == -1) {          IsICD = false;        }      }      if (i == 5) {       if (ValidChars.indexOf(Char) == -1) {          IsICD = false;        }      }          } if (IsICD == false) {  alert("Invalid format");  } else if (i == "") {  alert("No code was entered"); } else {  alert("Valid format"); }  return IsICD;}</script><!--    This script downloaded from www.JavaScriptBank.com    Come to view and download over 2000+ free javascript at www.JavaScriptBank.com-->


HTML
<p style="text-align: center;">Examples for valid ICD-10 codes: T86.88, T86.2 or N12<br>(<em>If the field is empty, the script returns true.</em>)</p><form id="myForm" name="myForm" method="post" onsubmit="return checkICD()" style="text-align: center;">Enter ICD-10 Code <input name="ICDfield" type="text" id="ICDfield">   <input type="submit" name="Submit" value="Check the code"></form><!--    This script downloaded from www.JavaScriptBank.com    Come to view and download over 2000+ free javascript at www.JavaScriptBank.com-->