/^[0-9]\s[0-9]/[0-9]$|^[0-9]/[0-9]$|^[0-9]$|^[0-9],[0-9]$|^[0-9].[0-9]$/.test("1 1") is giving true. Why? I want only following type of strings to return true to above check: "1 1/2", "1/2", "1,2", "1.2", "1"
Also, I need to allow ½ character. Its not 3 characters but 1. It is available in Swedish keyboard.
Also, I am checking this in onchange event of an asp.net textbox. If it returns false, I don't want page to postback and call the event handler of textbox's textchanged event. For this, I used event.preventDefault() but it does not work. Below is the markup of the textbox.
<asp:TextBox ID="gvtxtQty" CssClass="qty_input" runat="server" BackColor="#f4f6f7" Width="100px"
Text='<%# Eval("Qty")%>' OnTextChanged="gvtxtQty_TextChanged"></asp:TextBox>
And I register the change event for the textbox like below.
$(".qty_input").change(function (e) { fnVerifyQuantity(e, this) });
Function fnVerifyQuantity is as below:
function fnVerifyQuantity(e,o) {
var bol = /^[0-9]\s[0-9]\/[0-9]$|^[0-9]\/[0-9]$|^[0-9]$|^[0-9],[0-9]$|^[0-9].[0-9]$/;
//var bol = /[0-9]\s[0-9]\/[0-9]/;
var tf = bol.test(o.value);
if(tf=="false") e.preventDefault();
Please help.