-3

I need regular expression for allow only letters,numbers and white space but not allow special characters This is my code

<input type="text" name="station_name" class="form-control" data-validation="required" data-validation-regexp="/^[a-zA-Z ]*$/"  data-validation-error-msg="Please enter the valid Station Name" maxlength="50" value="<?php  echo $shop_name;?>">
Mitch Wheat
  • 295,962
  • 43
  • 465
  • 541
Janu J
  • 1
  • You are supposed to try something by yourself first... – Nijraj Gelani Jan 27 '16 at 05:39
  • Welcome to SO, please be a bit more specific when asking question: what have you tried, what do you expect, etc. See [how to ask](http://stackoverflow.com/help/how-to-ask) – Nehal Jan 27 '16 at 05:39
  • Check the answer:- http://stackoverflow.com/questions/18608954/how-to-prevent-user-from-entering-special-characters-in-text-box-when-length-is – Alive to die - Anant Jan 27 '16 at 05:40

2 Answers2

0

Try this:

<input type="text" name="station_name" class="form-control" data-validation="required" data-validation-regexp="/^[\s0-9A-Za-z]+$/"  data-validation-error-msg="Please enter the valid Station Name" maxlength="50" value="<?php  echo $shop_name;?>">
Vegeta
  • 1,319
  • 7
  • 17
0

Please correct your regexp from:

/^[a-zA-Z ]*$/

To:

/^[\s0-9A-Za-z]+$/

So finally code like:

<input type="text" name="station_name" class="form-control" data-validation="required" data-validation-regexp="/^[\s0-9A-Za-z]+$/"  data-validation-error-msg="Please enter the valid Station Name" maxlength="50" value="<?php  echo $shop_name;?>">
AddWeb Solution Pvt Ltd
  • 21,025
  • 5
  • 26
  • 57