0

I have a form with below code...

<table width="100%" border="0">
          <tr>
            <td class="text-1" height="43" width="40%">Full Name :<font color="#ff3a00">*</font></td>
            <td height="43" width="60%"><input name="txtbox" type="text" class="txtbox" required/></td>
          </tr>

          <tr>
            <td height="43" class="text-1">&nbsp;</td>
            <td height="43"><input name="" class="submit-btn" type="submit" value="Submit" /></td>
          </tr>
        </table>

My issue is that whenever a user fills the Full Name textbox with SPACES.. the required attribute allows it..??

How can i stop if just SPACES are filled by any user...

Please let me know..

Also, i tired using patter in inputbox..

Robby Cornelissen
  • 91,784
  • 22
  • 134
  • 156
Dhawal Mhatre
  • 435
  • 2
  • 8
  • 28

3 Answers3

0

You can use pattern attribute of HTML5 and give regex expression to avoid spaces

<table width="100%" border="0">
  <tr>
    <td class="text-1" height="43" width="40%">Full Name :<font color="#ff3a00">*</font>
    </td>
    <td height="43" width="60%">
      <input name="txtbox" type="text" class="txtbox" pattern="^\S+$" required/>
    </td>
  </tr>

  <tr>
    <td height="43" class="text-1">&nbsp;</td>
    <td height="43">
      <input name="" class="submit-btn" type="submit" value="Submit" />
    </td>
  </tr>
</table>
Tushar
  • 85,780
  • 21
  • 159
  • 179
Shehary
  • 9,926
  • 10
  • 42
  • 71
0
<table width="100%" border="0">
          <tr>
            <td class="text-1" height="43" width="40%">Full Name :<font color="#ff3a00">*</font></td>
            <td height="43" width="60%"><input name="txtbox" type="text" class="txtbox" pattern="[A-Za-z0-9\S]{1,25}" required/></td>
          </tr>

          <tr>
            <td height="43" class="text-1">&nbsp;</td>
            <td height="43"><input name="" class="submit-btn" type="submit" value="Submit" /></td>
          </tr>
        </table>
jhegeman2
  • 59
  • 6
0
<input name="txtbox" type="text" class="txtbox" required pattern="[A-Za-z]{1,}"/>

EXPLANATION:

the attribute pattern requires the input to match the regular expression pattern THE PATTERN [A-Za-z]{1,}

[A-Za-z] Any letter from A-Z or a-z

{1,} Minimum length is 1 and no specified maximum length

Sam Battat
  • 5,725
  • 1
  • 20
  • 29