JavaScript - Regular expression to accept numbers and a word NA

Asked By abinav shankar on 25-May-13 03:05 PM
I have tried a regex-pattern that should accept only numbers and NA but I cannot arrive at a solution.Any guidance on this will be of great help
Robbe Morris replied to abinav shankar on 25-May-13 04:11 PM
Here is the number only portion of the pattern.

return Regex.Replace(text, @"(?i)[^0-9]", string.Empty).Trim();

Sandeep Mittal replied to abinav shankar on 26-May-13 12:55 AM
You can simply apply regular expression for numeric value only and put "NA" in or condition
private bool IsNumericOrNA(string str)
  if (Regex.IsMatch(str, "^\\d{1,10}$") || str =="NA")
    return true;
    return false;