Note that there are some explanatory texts on larger screens.

plurals
  1. POJavascript: Validate field (on a form) so that it can only have Letters, 1 hyphen allowed, and 1 apostrophe allowed
    primarykey
    data
    text
    <p>this is my first time really coding in javascript and I've come to a dead end on my part. I need to make a function (no RegExp allowed unfortunately) that allows my pizza form to validate a user's input. To make sure it ONLY has letters (no numbers, no spaces, no special characters aside from hyphen and apostrophe). </p> <p>The user may use ONE apostrophe (with a letter before and after it). and the user may use ONE hyphen (with a letter before it and after it), the user may also use an apostrophe and hyphen at the same time as long as separated by a letter. And once the user clicks submit button to cgi, my end result is to display the name in all caps. </p> <p>example;</p> <p>enter client name: mike or m'ike or m'i-ke</p> <p>(click submit pizza order)</p> <p>result: MIKE or M'IKE or M'I-KE.</p> <p>so far this is what I have:</p> <pre><code>function validatefield01(errMessages) { // Get the content of fieldOne var entry1_info = document.pizza.field01.value; // error condition will show if character count is less than 4 or greater than 15 if ((entry1_info.length &lt;4) &amp;&amp; (entry1_info.length &lt;15)) // error message to be displayed { errMessages += " &lt;li&gt;Minimum characters for Client Surname is 4 maximum 15\n"; errMessages += " must use characters only, Apostrophe ( ' ) or hyphen (-) is acceptable.&lt;/li&gt;\n"; } return errMessages; for(var i=0; i&lt;entry1_info.length; i++) { ch = entry1_info.length.charAt(i); if(ch !=' ' &amp;&amp; ch !='.') return false; } </code></pre> <p>to better explain what's going on here. This function will be called in my main function to popup a window displaying all the errors should any have been made (created in an if statement, which does work), in my else statement i have this</p> <pre><code>else { field01=field01.substring(0).toUpperCase(); return true; // No errors - return to browser and submit form } } // End of main function </code></pre> <p>so what's happening right now is, if lower case letters are entered the form wont accept it, but if letters are entered in caps the form will accept it and it will show the name in the cgi. I don't know how to fix that, the user can enter in lowercase and it should accept but in the cgi it should be changed to uppercase, which is why i have that .toUpperCase()...</p> <p>thank you for the help!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload