tôi đang cố gắng để xác nhận nếu số điện thoại là một chữ số hay không: -Members số điện thoại với một ruby regex
Đây là user.rg tôi
number_regex = /\d[0-9]\)*\z/
validates_format_of :phone, :with => number_regex, :message => "Only positive number without spaces are allowed"
Đây là view.html của tôi .haml
%li
%strong=f.label :phone, "Phone Number"
=f.text_field :phone, :placeholder => "Your phone number"
Đây là bộ điều khiển
def edit_profile
@user = current_user
request.method.inspect
if request.method == "POST"
if @user.update_attributes(params[:user])
sign_in(@user, :bypass => true)
flash[:success] = "You have updated your profile successfully"
redirect_to dashboard_index_path
else
flash[:error] = "Profile could not be updated"
render :action => "edit_profile"
end
end
end
Khi tôi nhập số vào trường văn bản lần đầu tiên nó xác nhận hợp lệ, nhưng nếu tôi nhập đúng định dạng và sau đó thử nhập sai định dạng, bỏ qua xác thực và tôi nhận được thông báo flash rằng cấu hình đã được cập nhật thành công, tuy nhiên giá trị sai (có chữ cái) không được lưu.
Điều gì có thể là vấn đề ở đây?
Ít nhất khử trùng lĩnh vực này một chút. Khi tôi nhận được các tin nhắn như 'không có khoảng trống nào được cho phép' tôi giống như "noobs một lần nữa". – Reactormonk