1

Is it possible to create a mysql field which will only accept the characters a-zA-Z ?

amh15
  • 305
  • 2
  • 8
user722756
  • 633
  • 1
  • 5
  • 9

1 Answers1

2

You will need to look at the REGEX replace function detailed here How to count words in MySQL / regular expression replacer? (involves a UDF though) which you would need to use on a BEFORE INSERT trigger.

Alternatively you can look at sanitising the input in your code prior to insertion. This would be a more efficient method as most languages i.e. PHP support Regex, so a simple regex replace before insertion would be trivial.

MySQL unfortunately has no way to specify constraints such as this on columns.

Community
  • 1
  • 1