Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 320
  • Last Modified:

Validating string and numeric values from regular expression

Hi Experts,


I have an issue in my below regular expression:

1. I want my string to accept any string between a-z or A-Z along with the space.

I have below expression for this
^([a-zA-Z\\.\\,\\(\\)\\-_]|\\s)*$

Please help me fixing this expression


2. I want my numeric field should accept numeric values, but it should not accept any negative values

Please help me fixing below expression

^([0-9]|\\s)*$

Thanks
0
tia_kamakshi
Asked:
tia_kamakshi
2 Solutions
 
ozoCommented:
any string between a-z or A-Z along with the space
^[a-zA-Z ]+$

I want my numeric field should accept numeric values, but it should not accept any negative values
^[0-9]+$
0
 
Ken ButtersCommented:
1. Alpha with space: "^[a-zA-Z ]+$"
2. Numeric only "^[0-9]+$"
0
 
tia_kamakshiAuthor Commented:
Thanks,

I will check and confirm

Regards,
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
Terry WoodsIT GuruCommented:
The given patterns for numeric values don't accept decimals. If you do want to accept decimal values, please indicate which of the following cases should be considered valid:
0
0.0
.1
.0
.
1
1.0
1.10
01.1
01
1,000.00
0
 
tia_kamakshiAuthor Commented:
Applogies, I will check and confirm tommorow.

I don't need any decimal values in my numeric fields. Still I will check and confirm

Regards
0
 
GreggCommented:
One thing to point out (If I recall correctly), back slashes arent necessary inside your char class.

Note that the only special characters or metacharacters inside a character class are the closing bracket (]), the backslash (\), the caret (^) and the hyphen (-). The usual metacharacters are normal characters inside a character class, and do not need to be escaped by a backslash.  

Scroll down to "Metacharacters Inside Character Classes" on this page: http://www.regular-expressions.info/charclass.html
0
 
tia_kamakshiAuthor Commented:
Many Thanks.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now