fightstarr20
fightstarr20

Reputation: 12628

Regex do not allow only numbers

I am trying to use regex to validate some data, I need it to match the following rules...

I have this regex so far http://regex101.com/r/nC4hZ8...

(?:\s*[a-zA-Z0-9]{2,}\s*)*

This is working apart from it allows it to consist of all numbers. So for example the following test data should all fail....

47
4
83874

But the following should pass

47 apple
apple

Can anyone help?

Upvotes: 5

Views: 2521

Answers (2)

Valerij
Valerij

Reputation: 27758

([a-z][a-z0-9]+|[a-z0-9]+[a-z]|[a-z0-9]+[a-z][a-z0-9]+)

EDIT: matching space too

([a-z][a-z0-9 ]+|[a-z0-9 ]+[a-z]|[a-z0-9 ][a-z]+[a-z0-9 ])

Upvotes: 1

anubhava
anubhava

Reputation: 786291

You can use this regex:

^(?![0-9]+$)[a-zA-Z0-9 ]{2,}$

Online Demo

Upvotes: 4

Related Questions