- The first Regular Expression Library on the Web!

Please support RegExLib Sponsors


Regular Expression Details

Title Test Find Pattern Title
^\d* \d*\/{1}\d*$|^\d*$
This expression is used to validate fractions (entered as strings). It will also accept non-fractional entries. Simple, but effective.
100 | 1 1/2 | 1232 5/8
a 1/2 | abc | a b/c
Author Rating: Not yet rated. Kevin Hillabolt
Your Rating
Bad Good

Enter New Comment

Spammers suck - we apologize. Please enter the text shown below to enable your comment (not case sensitive - try as many times as you need to if the first ones are too hard):

Existing User Comments

Title: Suggestion
Name: Guest
Date: 10/8/2014 9:34:42 AM
Although this might be 10+ years too late, may I suggest adding a \s* in between the first ^\d* and second \d* to allow for any amount of white space (including none) and make the regex a little more effective. ^\d*\s?\d*\/{1}\d*$|^\d*$

Title: Re Neither works!
Name: Michael Ash
Date: 8/5/2004 1:46:23 PM
Mostly likely that's because the ignorewhitespaces property has been turned on for the site to allow comments so spaces in the pattern are being ignored. It probably wasn't on when the expression was added. Try changing the spaces in the pattern to \x20 or just put a \ in front of the space.

Title: Neither works!
Name: Michael Lang
Date: 8/5/2004 10:38:49 AM
I tried this one and the one in the comment by MikeH. I used this site's test page to test them. An item from the sample matches does not really match! 1 1/2

Title: Doesn't work
Name: MikeH
Date: 8/6/2003 5:08:38 PM
Doesn't work as is for fractions without a whole number (even though it says it does). It should be: ^(\d* )?\d*\/{1}\d*$

Copyright © 2001-2018, | ASP.NET Tutorials