Я пытаюсь проверить, является ли номер телефона цифрой или нет: -
Это мой user.rg
number_regex = /\d[0-9]\)*\z/
validates_format_of :phone, :with => number_regex, :message => "Only positive number without spaces are allowed"
Это мой view.html.haml
%li
%strong=f.label :phone, "Phone Number"
=f.text_field :phone, :placeholder => "Your phone number"
Это контроллер
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
Когда я ввожу число в текстовое поле в первый раз, оно правильно проверяется, но если я ввожу правильный формат, а затем пытаюсь ввести неправильный format он пропускает проверки и я получаю флеш-сообщение о том, что профиль был успешно обновлен, однако неправильное значение (с буквами) не сохраняется
В чем может быть проблема?