# Other Languages > jQuery >  Validate Input

## dday9

I'm wanting to validate a required input by checking if:
There is a valueThe value matches the pattern

I have tried this:


```
if($(this).val() === "" || ($(this).prop('pattern') !== "" && $(this).val().match($(this).prop('pattern'))))
```

And it returns True if the value is not an empty string but it also returns True regardless of if the pattern is a match or not. Any idea on how to do this?

For what it's worth, here is the fiddle that I've been working on: http://codepen.io/anon/pen/XdbaBG
I'm making a step-by-step form.

----------


## tr333

Any reason why you're not using the form-validation attributes "required" and "pattern"?  Alternatively, if that's not enough you could use the jQuery Validation plugin?  This plugin also supports regex validation similar to the HTML5 forms pattern attribute.

----------


## Ecniv

Shouldnt it be != not !== ?
Possibly when you dont have anything its returning null. but this might change to 'null' which isnt equal "".
Not sure if the match would then return true ...?

----------


## Sherin

```
   var pattern= new RegExp("pattern");
   if(($(#id).val()) && $(#id).val().match(pattern)){
    alert("True");
   }
```

----------

