java - I need help on regular expression to allow number with character -


condition:

123           not valid 123         valid abc123        valid abc123ab      valid 

i have apply regular expression compulsory character number?

this match string starting optional set of digits followed combination of white spaces, letters , digits. still matches 123_ (that's 123 followed space `)

^\d*[\sa-za-z0-9]+$ 

the following check if have @ least 1 letter in string combined optional digits, white spaces , letters.

[a-za-z\s\d]*[a-za-z]+?[a-za-z\s\d]* 
  • [a-za-z\s\d] match single character present in [].
  • quantifier * : between 0 , unlimited times, many times possible, giving needed [greedy]
  • quantifier: +? between 1 , unlimited times, few times possible, expanding needed [lazy]

Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -