<p>In my user model, I have an attribute called "nickname" and validates as such:</p>

<blockquote>
  <p>validates_format_of :nickname, :with => /[a-zA-Z0-9]$/, :allow_nil => true</p>
</blockquote>

<p>However, it is currently letting this string pass as valid:</p>

<p>a?c</p>

<p>I only want to accept alphanumeric strings - does anyone know why my regular expression is failing?  If anybody could suggest a better regular expression, I'm all ears.</p>

You need to anchor the pattern on both sides:
```
```
/^[a-zA-Z0-9]+$/
```
```