w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Java Regex: check if a sentence contains only alphabet and numbers

Change your regex to: ^[a-zA-Z0-9s]+$ it'll allow only characters, numbers and spaces as required. pay attention that part of the "magic" is the use of ^ and $ which force a full match (from beginning to end).

Further, the reason I've used a-zA-Z0-9 instead of w is that w includes _ which doesn't fit the requirements.





© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.