JavaScript - Regular Expression - Asked By waseem kaleem on 19-Jul-11 01:39 PM

I have following regular expresstion
var reg=/\d{5}/
reg.test(txtname)
txtname is textbox
when I enter numeric 5 values it returns false.
can any one solve this problem
Web Star replied to waseem kaleem on 19-Jul-11 01:48 PM
your regular expression is wrong to validate 5 digit numeric
correct this as folllows

reg="^\d{5}$";    // 5 numeric digits, such as a US ZIP code.
if you want to any numeric than simply use
\d Matches any decimal digit. Equivalent to [\p{Nd}] for Unicode and [0-9] for non-Unicode, ECMAScript behavior.
dipa ahuja replied to waseem kaleem on 19-Jul-11 01:58 PM
use this ragularExpression:

var re5digit=/^\d{5}$/
Jitendra Faye replied to waseem kaleem on 19-Jul-11 11:52 PM
Use this this-

If Not Regex.Match(textBox1.Text"^\d{5}$").Success Then

   ' zip code was incorrect
   MessageBox.Show("Invalid zip code")

   Return
End If

Use and let me know.
waseem kaleem replied to dipa ahuja on 20-Jul-11 09:45 AM
Is this is correct for unicode characters [\p{L}]?