I am trying to check if the phone number is a digit or not: -
This is my user.rg
number_regex = /\d[0-9]\)*\z/ validates_format_of :phone, :with => number_regex, :message => "Only positive number without spaces are allowed"
This is my view.html.haml
%li %strong=f.label :phone, "Phone Number" =f.text_field :phone, :placeholder => "Your phone number"
This is the controller
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
When I enter the number in the text box for the first time, it checks in advance, but if I enter the correct format and then try to enter the wrong format, it will skip the check and I get a message that the profile was updated successfully, but the value is incorrect ( with letters) is not saved.
What could be the problem?
Dev r
source share