JScript Trim function

Results 1 to 2 of 2

Thread: JScript Trim function

  1. #1
    Join Date
    Dec 1969

    Default JScript Trim function

    Hey guys, I have a simple (i think) problem but it seems to be confusing the heck out of me :(<BR><BR>I have a textbox in my form that I dont want to allow the user to enter blanks as the value. So to do this, i figure I&#039;d just take out all the spaces before and after the inputed text so then I can just do a (if(text == "") then alert(message))....but this is giving me problems....any ideas of what i am doing wrong or if there is an easier way??? <BR><BR>Below is my code: (that may help)<BR><BR>function validate (){<BR><BR> var qtext = document.new_questionForm.qtext.value;<BR> <BR> if(qtext == "") //user trying to enter spaces as text<BR> {<BR> alert("Please Enter The Question Text");<BR> }<BR> else<BR> {<BR> continue;<BR> }<BR>}

  2. #2
    Join Date
    Dec 1969
    Los Angeles, CA

    Default RE: JScript Trim function

    function trim(s) { return s.replace(/(^s+)&#124(s+$)/g, "") }<BR><BR><BR><BR>you will then check the lenght of the value returned by this function to make sure it is more than 0<BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts